DrewDog_21
Jan 17th, 2001, 07:34 PM
Help! I am new to C++ and need to write a routine to pass a 2 dimensional array into a function that will determine whether or not the array is a Magic Square. On the function call:
IsMagic = TestMagic(myArray[500][500], dimension);
I get the error
passing `int' to argument 1 of `TestMagic(int(*)[500], int)' lacks a cast.
Why? And why does it show as int(*)[500] instead of int[500][500]?
Thanks
Andrew
#include<iostream.h>
bool TestMagic(int PassedSquare[500][500], int ArrayDimension)
//this is not yet all of the code that will go into this function
{
int sum;
for (int x = 1; x <= ArrayDimension; x++)
{
sum = sum + PassedSquare[x][x];
}
cout << endl;
cout << "Left-Right Diagonal is: " << sum;
return true;
}
int main()
{
int myArray[500][500];
int dimension;
bool IsMagic;
cout << "Enter array size (minimum 1, maximum 500), or 0 to exit the program: ";
cin >> dimension; //user enters desired array size
while (dimension > 0)
{
//instruct user to enter a value for each array element
for (int x = 1; x <= dimension; x++)
{
for (int y = 0; y < dimension; y++)
{
cout << "Enter the value for " << x << ", " << y << ": ";
cin >> myArray[x][y];
cout << endl;
}
}
//call function TestMagic and pass it the array and its dimensions
//this is where I get the error
IsMagic = TestMagic(myArray[500][500], dimension);
if (IsMagic = true)
cout << "Yes";
else
cout << "No";
cout << endl;
cout << "Enter array size (minimum 1, maximum 500), or 0 to exit the program: ";
cin >> dimension; //user enters desired array size
}
return 0;
}
IsMagic = TestMagic(myArray[500][500], dimension);
I get the error
passing `int' to argument 1 of `TestMagic(int(*)[500], int)' lacks a cast.
Why? And why does it show as int(*)[500] instead of int[500][500]?
Thanks
Andrew
#include<iostream.h>
bool TestMagic(int PassedSquare[500][500], int ArrayDimension)
//this is not yet all of the code that will go into this function
{
int sum;
for (int x = 1; x <= ArrayDimension; x++)
{
sum = sum + PassedSquare[x][x];
}
cout << endl;
cout << "Left-Right Diagonal is: " << sum;
return true;
}
int main()
{
int myArray[500][500];
int dimension;
bool IsMagic;
cout << "Enter array size (minimum 1, maximum 500), or 0 to exit the program: ";
cin >> dimension; //user enters desired array size
while (dimension > 0)
{
//instruct user to enter a value for each array element
for (int x = 1; x <= dimension; x++)
{
for (int y = 0; y < dimension; y++)
{
cout << "Enter the value for " << x << ", " << y << ": ";
cin >> myArray[x][y];
cout << endl;
}
}
//call function TestMagic and pass it the array and its dimensions
//this is where I get the error
IsMagic = TestMagic(myArray[500][500], dimension);
if (IsMagic = true)
cout << "Yes";
else
cout << "No";
cout << endl;
cout << "Enter array size (minimum 1, maximum 500), or 0 to exit the program: ";
cin >> dimension; //user enters desired array size
}
return 0;
}