I need to fix this program , i've been tryingto fix it but it wast work
there are to major prblem in this program both of then in the outputs
the first it repeats the output twice
the second the range funftion doesnt work
my program is Magic Square
and here is the code it is in C++
#include<iostream>
#include<iomanip>
using namespace std;
bool checkColumns ( int theSquare[][4], const int numRows, const int magicvalue);
bool checkRows ( int theSquare[][4], const int numRows, const int magicvalue);
bool checkDiagonals ( int theSquare[][4], const int numRows, const int magicvalue);
bool checkRange ( int theSquare[][4], const int numRows, const int magicvalue );
int main()
{
int theSquare[4][4];
int numRows;
int magicvalue=34;
cout<<"The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number."<<endl;
for (int row= 0; row<4; row++)
{
cout <<"Please enter the 4 values for row " <<row<< " , seperated by spaces: ";
for (int col=0; col<4; col++)
cin >> theSquare[row][col];
}
checkRows (theSquare, numRows, magicvalue);
checkColumns (theSquare, numRows, magicvalue);
checkDiagonals (theSquare, numRows, magicvalue);
checkRange (theSquare, numRows, magicvalue);
bool Diagonals= checkDiagonals (theSquare, numRows, magicvalue);
bool Rows = checkRows (theSquare, numRows, magicvalue);
bool Columns = checkColumns (theSquare, numRows, magicvalue);
bool Range = checkRange (theSquare, numRows, magicvalue);
if (Diagonals==true && Rows==true && Columns==true && Range==true)
cout << "MAGIC: YES" << endl;
else
cout << "MAGIC: NO" << endl;
return 0;
}
//////////////////////////////////////
bool checkRows( int theSquare[][4], const int numRows, const int magicvalue)
{
int row1=theSquare[0][0]+theSquare[0][1]+theSquare[0][2]+theSquare[0][3];
int row2=theSquare[1][0]+theSquare[1][1]+theSquare[1][2]+theSquare[1][3];
int row3=theSquare[2][0]+theSquare[2][1]+theSquare[2][2]+theSquare[2][3];
int row4=theSquare[3][0]+theSquare[3][1]+theSquare[3][2]+theSquare[3][3];
if (row1==34&&row2==34&&row3==34&&row4==34)
{
cout <<"ROWS: VALID"<<endl;
return true;
}
else
{
cout << "ROWS:";
if( row1!=magicvalue)
cout<<" 0 ";
if( row2!=magicvalue)
cout<<" 1 ";
if( row3!=magicvalue)
cout<<" 2 ";
if( row4!=magicvalue)
cout<<" 3 "<<endl;
return false;
}
}
//////////////////////////////////////////////////////////////////
bool checkColumns ( int theSquare[][4], const int numRows, const int magicvalue )
{
int col1= theSquare[0][0] + theSquare[1][0] + theSquare[2][0]+ theSquare[3][0];
int col2= theSquare[0][1] + theSquare[1][1] + theSquare[2][1]+ theSquare[3][1];
int col3= theSquare[0][2] + theSquare[1][2] + theSquare[2][2]+ theSquare[3][2];
int col4= theSquare[0][3] + theSquare[1][3] + theSquare[2][3]+ theSquare[3][3];
if ( col1==magicvalue&&col2==magicvalue&&col3==magicvalue&&col4==magicvalue)
{
cout <<"COLS: VALID"<<endl;
return true;
}
else
{
cout << "COLS:";
if( col1!=magicvalue)
cout<<" 0 ";
if( col2!=magicvalue)
cout<<" 1 ";
if( col3!=magicvalue)
cout<<" 2 ";
if( col4!=magicvalue)
cout<<" 3 "<<endl;;
return false;
}
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
bool checkDiagonals ( int theSquare[][4], const int numRows, const int magicvalue )
{
int dia1 = theSquare[0][0] + theSquare[1][1] + theSquare[2][2]+ theSquare[3][3];
int dia2= theSquare[0][3] + theSquare[1][2] + theSquare[2][1]+ theSquare[3][0];
if ( dia1==magicvalue && dia2==magicvalue)
{
cout <<"DIAG: VALID"<<endl;
return true;
}
else
{
cout<<"DIAG: ";
if( dia1!=magicvalue)
cout<<"0 ";
if( dia2!=magicvalue)
cout<<"1"<<endl;;
return false ;
}
}
////////////////////////////////////////////////////
bool checkRange ( int theSquare[][4], const int numRows, const int magicvalue )
{
int range[17];
int foo=0;
cout<<"RANG: ";
for(int bar=0; bar<4; bar++)
{
for(int j=0; j<4; j++)
{
if(theSquare[bar][j]>16 || theSquare[bar][j]<1)
{
cout<<theSquare[bar][j]<<" ";
foo++;
}
else
if(range[theSquare[bar][j]]== j )
{
cout<<theSquare[bar][j]<<" ";
foo++;
}
else
range[theSquare[bar][j]]= j;
}
}
if (foo > 0)
{ cout << endl;
return false;
}
else
{
cout<<" Valid"<<endl;
}
return true;
}