So I need to make a code with these functions. the checkMatrix has to be a boolean and the getData has to pass the 1D array. How do I check the magic square with a 2D array? instructions :Write a program that will prompt the user for the integers to fill a 3 x 3 two dimensional array that builds a table. Once the data is entered the program checks to see if the table forms a magic square. When complete have the program prompt the user to see if they want to test another square and loop back accordingly. Note: Your solution should validate the input to the program from erroneous input. This means that your program checks to see that the data entered is numeric and in the range of 1 and 9 inclusive and not duplicate data can be entered. Hint: A one dimensional array could be used to keep a tally of which numbers have been assigned to the magic square. Program Style= The program must contain the following functions that carry out the operations in the given descriptions. Use the function names given. All data must be passed to required functions by value or reference; no global variables are allowed. Function Description= main= This function explains the magic square directions, organizes calls to other functions, and reports final result. getData= This function gets and validates the 9 digits entered by the user to fill the 3 x 3 table. Must implement passing of array data. checkMatrix= This function is passed the array data matrix entered by the user determine if it is a magic square sequence and returns a Boolean as result of test.
#include <iostream>
#include <windows.h>
using namespace std;
int checkMatrix()
int getData(input[9] );
//prototypes
int main()
{
char repeat;
//declaration of variables
do
{
system("cls");
//clear screen between calculations
cout << "**********************************************************" << endl;
cout << "** CSC 175 Program #6 by Morgan Kelly **" << endl;
cout << "** **" << endl;
cout << "** Enter a magic square sequence by assigning a value **" << endl;
cout << "** from 1 to 9 to each location of a 3 by 3 table. **" << endl; **" << endl;
cout << "**********************************************************" << endl;
//header
getData(input[9]);
//call getData function
cout << "*************" << endl;
cout << "*" << input[0] << " " << input[1] << " " input [2] << "*" << endl;
cout << "*" << input[3] << " " << input[4] << " " input [5] << "*" << endl;
cout << "*" << input[6] << " " << input[7] << " " input [8] << "*" << endl;
cout << "*************" << endl;
if checkMatrix()= true
cout << "This is a magic square!" << endl;
else
cout << "This is not a magic square!" <<endl;
cout << "Want to check another table? (y/n): ";
cin >> repeat;
} while (repeat == 'y' or repeat == 'Y');
//repeat program and be able to calculate another table
return 0;
}
int getData(input[9])
{
int input[9];
//declaration of 1 dimensional array
while (input[9] >0 and input[9]<10)
{
cout << "Enter row 1 and column 1: ";
cin >> input[0];
cout << endl;
cout << "Enter row 1 and column 2: ";
cin >> input[1];
cout << endl;
cout << "Enter row 1 and column 3: ";
cin >> input[2];
cout << endl;
cout << "Enter row 2 and column 1: ";
cin >> input[3];
cout << endl;
cout << "Enter row 2 and column 2: ";
cin >> input[4];
cout << endl;
cout << "Enter row 2 and column 3: ";
cin >> input[5];
cout << endl;
cout << "Enter row 3 and column 1: ";
cin >> input[6];
cout << endl;
cout << "Enter row 3 and column 2: ";
cin >> input[7];
cout << endl;
cout << "Enter row 3 and column 3: ";
cin >> input[8];
cout << endl;
}
if cin.fail()
cin.clear();
cin.sync();
cout << "INVALID INPUT - ";
//validates for input(numbers) that are between 1 and 9 only
//input numbers from user and validate
return input[9];
}
bool checkMatrix()
{
if array1[]=array2[]
{return true;}
else
{return false;}
}