Grades program

Okay well the program is that I have to infile grades into an array. after I infile them I have to use that array and pass it into 4 different functions: find the lowest, highest and average grade and then find how many range from 50-59, 60-69, 70-79, 80-89, and 90-100. I have the following code and I keep getting zeros when I run the program. What am I doing wrong and how do I fix it? also I need a bit of help on how im supposed to do the grade distribution function.

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int highest(int [], int);
int lowest(int[], int);
double average(int[],int);
void gradeDistribution(int[],int);

int main()
{
const int SIZE=20;
int grades[SIZE];
double average=0.0;
int highest=0;
int lowest=0;
ifstream infile;
infile.open("values.txt");

for (int x=0; x<20; x++)
{
infile>>grades[x];
}
infile.close();

cout<<"The highest grade is: "<<highest<<endl;
cout<<"The lowest grade is: "<<lowest<<endl;
cout<<"The average grade is: "<<average<<endl;



system("pause");
return 0;

}

int lowest(int grades[],int SIZE)
{
int lowest=grades[0];
for(int count=1; count<SIZE; count++)
{
if(grades[count]<lowest)
lowest=grades[count];
}
return lowest;
}

int highest(int grades[],int SIZE)
{
int highest=grades[0];
for(int count=1; count<SIZE; count++)
{
if(grades[count]>highest)
highest=grades[count];
}

return highest;
}

double average(int grades[],int SIZE)
{
double average=0.0;
int total;
for(int count=0;count<SIZE; count++)
{
total+=grades[count];
}
average=total/20;
return average;
}

void gradeDistribution(int grades[],int SIZE)
{

}
Last edited on
the reason you kept getting 0 is because highest is both a variable name and a function name, so when you cout<<highest, you're basically saying, you want to see the value in variable highest BUT if you say highest(grades, SIZE), then I think you should expect the correct result.
I tried that before I posted. It gives me an error that says, "expression must have (pointer-to-) function type." :/
then you change either the function name "highest(int [], int);" to something else, maybe _highest, or the variable name in main() to something else.
In main(), the variables you declared, i.e. highest, average, lowest, remains unused, so I suggest you eliminate them.

EDIT: I implemented your code here: http://codepad.org/Gjlb6Uno
I could not use the fstream because the site does not permit working with files, so you just populate the grades[] with the content of inFile like
1
2
3
4
5
6
7
int x(0);
while(inFile)
{
cin>>grades[x];
x++;
}
inFile.close();
Last edited on
Topic archived. No new replies allowed.