views:

314

answers:

2
void display_totals();
int exam1[100][3];// array that can hold 100 numbers for 1st column
int exam2[100][3];// array that can hold 100 numbers for 2nd column
int exam3[100][3];// array that can hold 100 numbers for 3rd column 
int main()
{
    int go,go2,go3;
    go=read_file_in_array;
    go2= calculate_total(exam1[],exam2[],exam3[]);
    go3=display_totals;
    cout << go,go2,go3;
    return 0;
}
void display_totals()
{

    int grade_total;
    grade_total=calculate_total(exam1[],exam2[],exam3[]);
}   
int calculate_total(int exam1[],int exam2[],int exam3[])
{
    int calc_tot,above90=0, above80=0, above70=0, above60=0,i,j;
    calc_tot=read_file_in_array(exam[100][3]);
    exam1[][]=exam[100][3];
    exam2[][]=exam[100][3];
    exam3[][]=exam[100][3];
    for(i=0;i<100;i++);
        {
            if(exam1[i] <=90 && exam1[i] >=100)
                {
                    above90++;
                    cout << above90;
                }
        }
        return exam1[i],exam2[i],exam3[i];

}

int read_file_in_array(int exam[100][3])
{
  ifstream infile;  

  int num, i=0,j=0;
  infile.open("grades.txt");// file containing numbers in 3 columns
    if(infile.fail()) // checks to see if file opended
    {
        cout << "error" << endl;
    }
  while(!infile.eof()) // reads file to end of line
      {
          for(i=0;i<100;i++); // array numbers less than 100
          {
            for(j=0;j<3;j++); // while reading get 1st array or element
            infile >> exam[i][j];
            cout << exam[i][j] << endl;
          }
      }
  infile.close();
  return exam[i][j];
}
+1  A: 

The data type you're passing into calculate_total is wrong. C++ is seeing it as a pointer to an int. You're passing in a two dimensional array. You have to make the input type for your calculate_total function match the type of your array.

Also, all those extra []'s are invalid syntax. When passing in a variable defined as an array, pass in only the variable name.

// Invalid function call
f(myArray[]);

// Valid function call
f(myArray);

Inside of the actual function, what are you trying to do? Are you trying to modify an element of exam1, exam2, and exam3 to the value of exam[100][3]?

You're also missing the declaration of the array int exam[100][3]. I don't see it anywhere in your code.

And in the return of calculate_total, your return statement is malformed. You can only return one value, unlike Python where that would return a tuple containing three elements.

Sagekilla
The return statement is not ill-formed, it just probably doesn't do whats expected. Its using the comma operator and simply discards all but the last value.
Georg Fritzsche
im trying to sort the numbers in the array from the text file i read from. like 100-90 is a A, 90-80 is a B and so forth. and then go the next column and do the same thing and then the third and total all the A,B,C,D,F and print them on the screen at the end
i should be using i and j instead of 100 and 3
A: 

I observed the following issues in your code

  1. read_file_in_array requires parenthesis. go=read_file_in_array; //Invalid Function Call

  2. Passing Arrays as Arguments

  3. display_totals requires parenthesis

  4. Function prototypes were missing in the beginning

  5. display_totals will return nothing. But you are assigning it to a variable

  6. I don't understand what this calculate_total function is doing.

If this is your original code, there is a lot of issues in this code. I took this code as it is and compiled using Turbo c++ compiler. I got around 24 errors.

Can you please refactor your code and compile it.

Dinesh
i get these error C2059: syntax error : '] and i dont know why
Is this your complete source code? If not can you share the exact code for which you are getting this error.
Dinesh