-
C++ arrays question
Hi..I am writing a program to read a file containing student names and scores for 3 tests and output the highest in each test. What am I doing wrong? Thanks.(There are 6 students in the class)..
Code:
//Sample Program 12- A non-interactive program to calculate student grades.
//**************************************************************************************
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
const int SIZE=6;
int GetHighValue(int array[]);
int main()
{
int exam1Array[SIZE];
int exam2Array[SIZE];
int exam3Array[SIZE];
int i=0;
string name;
ifstream inFile;
inFile.open("grades.dat");
if(!inFile)
{
cout<<"Unable to open input file, program abnormally ended";
return 1;
}
for(i=0; i<SIZE; i++)
{
inFile>>name>>exam1Array[i]>>exam2Array[i]>>exam3Array[i];
}
GetHighValue(exam1Array[i]);
cout<<"The highest for exam 1 is"<<GetHighValue(exam1Array[i])<<endl;
GetHighValue(exam2Array[i]);
cout<<"The highest for exam 2 is"<<GetHighValue(exam2Array[i])<<endl;
GetHighValue(exam3Array[i]);
cout<<"The highest for exam 3 is"<<GetHighValue(exam3Array[i])<<endl;
return 0;
}
int GetHighValue(/*in*/ int array[])
{
int highScore=0;
int i=0;
for(i=0; i<SIZE; i++)
{
if(array[i]>highScore)
highScore=array[i];
}
return highScore;
}
-
what the error and where it happens
-
errors
One of the errors is that the first parameter int cannot be converted to int[]
-
Code:
GetHighValue(exam1Array);
cout<<"The highest for exam 1 is"<<GetHighValue(exam1Array)<<endl;
GetHighValue(exam2Array);
cout<<"The highest for exam 2 is"<<GetHighValue(exam2Array)<<endl;
GetHighValue(exam3Array);
cout<<"The highest for exam 3 is"<<GetHighValue(exam3Array)<<endl;
Note the missing [i]. Perhaps post the input file for further scrutiny.
-
Thanks!!
That part of the program works excellently now. Thanks!