R
Richard
I got 2 error in the program code below, but I don't know what they are and
how to fix it. Can anyone put it in compile and tell me what is wrong? I
am new to c++
#include <iostream>
#include <ostream>
using namespace std;
const int StudentNumber=2;
//structure declaration
struct Student
{
char Name[20];
int StudentID;
int TestScores[4];
float AverageTestScore;
char Grade;
}; Student
StudentInfo[StudentNumber];
// funciton phototype declaration
int GetStudentInfo(void);
void CalculateAverage(int &);
void DisplayStudentRecord(void);
int sum[];
void main()
{ //int sum=0;
GetStudentInfo();
CalculateAverage(sum[StudentNumber]);
DisplayStudentRecord();
}
int GetStudentInfo(void)
{
for(int count =0; count < StudentNumber; count++)
{
cout<<"What is the name of Student "<<count+1<<"?: ";
cin>>StudentInfo[count].Name;
cout<<"What is "<<StudentInfo[count].Name<<"'s ID number?: ";
cin>>StudentInfo[count].StudentID;
cout<<"Enter 4 test scores for "<<StudentInfo[count].Name<<":
"<<endl;
for (int count2=0; count2 < 4; count2++)
{
cin>>StudentInfo[count].TestScores[count2];
sum[count] += StudentInfo[count].TestScores[count2];
}
}
return sum;
}
void DisplayStudentRecord(void)
{
cout<<"Student Name\t"<<"StudentID\t"<<"Test Score
Average\t"<<"Grade\t"<<endl<<endl;
for (int count=0; count < StudentNumber; count++)
{
cout<<StudentInfo[count].Name<<"\t\t"<<StudentInfo[count].StudentID<<"\t\t"<<
StudentInfo[count].AverageTestScore<<"\t\t\t"<<StudentInfo[count].Grade<<endl;
}
}
void CalculateAverage(int &sum)
{ for(int count =0; count < StudentNumber; count++)
{
StudentInfo[count].AverageTestScore = float(sum[count])/4;
if (StudentInfo[count].AverageTestScore >= 90 &&
StudentInfo[count].AverageTestScore <=100)
{
StudentInfo[count].Grade = 'A';
}
if (StudentInfo[count].AverageTestScore >= 80 &&
StudentInfo[count].AverageTestScore <=89)
{
StudentInfo[count].Grade = 'B';
}
if (StudentInfo[count].AverageTestScore >= 70 &&
StudentInfo[count].AverageTestScore <=79)
{
StudentInfo[count].Grade = 'C';
}
if (StudentInfo[count].AverageTestScore >= 60 &&
StudentInfo[count].AverageTestScore <=69)
{
StudentInfo[count].Grade = 'D';
}
if (StudentInfo[count].AverageTestScore <59)
{
StudentInfo[count].Grade = 'F';
}
}
}
how to fix it. Can anyone put it in compile and tell me what is wrong? I
am new to c++
#include <iostream>
#include <ostream>
using namespace std;
const int StudentNumber=2;
//structure declaration
struct Student
{
char Name[20];
int StudentID;
int TestScores[4];
float AverageTestScore;
char Grade;
}; Student
StudentInfo[StudentNumber];
// funciton phototype declaration
int GetStudentInfo(void);
void CalculateAverage(int &);
void DisplayStudentRecord(void);
int sum[];
void main()
{ //int sum=0;
GetStudentInfo();
CalculateAverage(sum[StudentNumber]);
DisplayStudentRecord();
}
int GetStudentInfo(void)
{
for(int count =0; count < StudentNumber; count++)
{
cout<<"What is the name of Student "<<count+1<<"?: ";
cin>>StudentInfo[count].Name;
cout<<"What is "<<StudentInfo[count].Name<<"'s ID number?: ";
cin>>StudentInfo[count].StudentID;
cout<<"Enter 4 test scores for "<<StudentInfo[count].Name<<":
"<<endl;
for (int count2=0; count2 < 4; count2++)
{
cin>>StudentInfo[count].TestScores[count2];
sum[count] += StudentInfo[count].TestScores[count2];
}
}
return sum;
}
void DisplayStudentRecord(void)
{
cout<<"Student Name\t"<<"StudentID\t"<<"Test Score
Average\t"<<"Grade\t"<<endl<<endl;
for (int count=0; count < StudentNumber; count++)
{
cout<<StudentInfo[count].Name<<"\t\t"<<StudentInfo[count].StudentID<<"\t\t"<<
StudentInfo[count].AverageTestScore<<"\t\t\t"<<StudentInfo[count].Grade<<endl;
}
}
void CalculateAverage(int &sum)
{ for(int count =0; count < StudentNumber; count++)
{
StudentInfo[count].AverageTestScore = float(sum[count])/4;
if (StudentInfo[count].AverageTestScore >= 90 &&
StudentInfo[count].AverageTestScore <=100)
{
StudentInfo[count].Grade = 'A';
}
if (StudentInfo[count].AverageTestScore >= 80 &&
StudentInfo[count].AverageTestScore <=89)
{
StudentInfo[count].Grade = 'B';
}
if (StudentInfo[count].AverageTestScore >= 70 &&
StudentInfo[count].AverageTestScore <=79)
{
StudentInfo[count].Grade = 'C';
}
if (StudentInfo[count].AverageTestScore >= 60 &&
StudentInfo[count].AverageTestScore <=69)
{
StudentInfo[count].Grade = 'D';
}
if (StudentInfo[count].AverageTestScore <59)
{
StudentInfo[count].Grade = 'F';
}
}
}