Solved
magic square 4*4
Posted on 2004-11-26
need help completing program with specs below
no global variables
2d arrays
use these functions declared
bool checkRows (int theSquare[][4], const int numRows, const int magicvalue);
function takes the square to check, # of rows to process and the magic value to check for. check all 4 rows for the magic value and return true of false depending on if all rows add upto the magic value. while checking rows, output which rows are bad if any are
same for columns and diagnols
#include<iostream>
#incldue<cmath>
using namespace std;
int main()
{
bool checkRows (int theSquare[][4], const int numRows, const int magicvalue);
bool checkColumns (int theSquare[][4], const int numRows, const int magicvalue);
bool checkDiagnols (int theSquare[][4], const int numRows, const int magicvalue);
checkUnique(); // will check to see if no # is used more than once
checkRange(); // will check to see range is 1to 16
int sum;
cout << "Please enter the 4 values for row 1, separated by spaces:";
cin >> num1 >> num2 >> num3 >> num4;
cout << "Please enter the 4 values for row 1, separated by spaces:";
cin >> num1 >> num2 >> num3 >> num4;
cout << "Please enter the 4 values for row 1, separated by spaces:";
cin >> num1 >> num2 >> num3 >> num4;
cout << "Please enter the 4 values for row 1, separated by spaces:";
cin >> num1 >> num2 >> num3 >> num4;
checkRows ();
checkColumns ();
checkDiagnols ();
checkUnique();
checkRange();
return 0;
}
bool checkRows (int theSquare[][4], const int numRows, const int magicvalue)
{ // check row sums
for (i = 0; i < 4; i++)
{
sum = 0;
for (j = 0; j < N; j++)
{
sum = sum + M[i][j];
}
}
}
bool checkColumns (int theSquare[][4], const int numRows, const int magicvalue)
{ // check column sums
for (j = 0; j < N; j++)
{
sum = 0;
for (i = 0; i < N; i++)
{
sum = sum + M[i][j];
}
}
}
bool checkDiagnols (int theSquare[][4], const int numRows, const int magicvalue)
{
sum = 0;
for (i = 0; i < N; i++)
{
sum = sum + M[i][i];
}