Results 1 to 2 of 2

Thread: 'lacks a cast' error - new to C++

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Unhappy

    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

    Code:
    #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;
       }

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374
    never mind, the line

    IsMagic = TestMagic(myArray[500][500], dimension);

    should have been

    IsMagic = TestMagic(myArray, dimension);

    'cause the first one only passes element [500][500]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width