Little bit help for Array Structure
I finished most of code as you guys see below, however, the code only summaries the highest final score of student, doesnt show the "Number" of student who got highest final score.(In fact, the "Number" of the student doesnt match the student who got the highest score) I tried couple times, but failed..please someone gives me a hint or explain why that part of my code is wrong(I have bolded it already)~~Thank you so much~~!
Code:
#include <iostream.h>
#include <iomanip>
using namespace std;
const int lscore=7, qscore=5, fscore=1;
struct studentinfo
{
char name[60];
int lab[lscore];
int quiz[qscore];
int final[fscore];
};
int main()
{
fstream outFile;
const int snum=10;
studentinfo student[snum];
int Qindex, Lindex, Findex, index, num, qtotal, ltotal, ftotal, hscore, hs, Hscore, Hs;
float qavg, lavg, favg;
cout<<"Enter number of students: ";
cin>>num;
for (index=0; index<num; index++)
{
cout<<"Enter the name of student #"<<index+1<<": ";
cin.ignore();
cin.getline(student[index].name, 60);
for (Qindex=0; Qindex<qscore; Qindex++)
{
cout<<"Enter quiz "<<Qindex+1<<" for student "<<index+1<<": ";
cin>>student[index].quiz[Qindex];
}
cout<<endl;
for (Lindex=0; Lindex<lscore; Lindex++)
{
cout<<"Enter lab "<<Lindex+1<<" for student "<<index+1<<": ";
cin>>student[index].lab[Lindex];
}
cout<<endl;
for (Findex=0; Findex<fscore; Findex++)
{
cout<<"Enter final score for student "<<index+1<<": ";
cin>>student[index].final[Findex];
}
cout<<endl;
}
for (index=0; index<num; index++)
{
cout<<"Summary for student #"<<index+1<<endl;
cout<<"Name of Student "<<student[index].name<<endl;
cout<<"Quiz Scores: ";
for (Qindex=0; Qindex<qscore; Qindex++)
{
cout<<student[index].quiz[Qindex]<<" ";
}
cout<<" Avg quiz score = ";
qtotal=0;
for (Qindex=0; Qindex<qscore; Qindex++)
{
qavg=((qtotal+=student[index].quiz[Qindex])/(qscore*1.0));
}
cout<<setprecision(3)<<qavg<<endl;
cout<<"Lab Score: ";
for (Lindex=0; Lindex<lscore; Lindex++)
{
cout<<student[index].lab[Lindex]<<" ";
}
cout<<" Avg quiz score = ";
ltotal=0;
for (Lindex=0; Lindex<lscore; Lindex++)
{
lavg=((ltotal+=student[index].lab[Lindex])/(lscore*1.0));
}
cout<<setprecision(3)<<lavg<<endl;
cout<<"Final Exam Score = ";
for (Findex=0; Findex<fscore; Findex++)
{
cout<<student[index].final[Findex];
}
cout<<endl;
}
hscore=student[0].final[0];
ftotal=0;
hs=0;
for (index=0; index<num; index++)
{
for (Findex=0; Findex<fscore; Findex++)
{
if(student[index].final[Findex]>hscore)
hscore=student[index].final[Findex];
hs=index;
favg=((ftotal+=student[index].final[Findex])/(num*1.0));
}
}
Hscore=hscore;
Hs=hs;
cout<<"Highest score for final = "<<Hscore<<" by student #"<<Hs<<", ";
cout<<setprecision(4)<<"Avg for final = "<<favg<<endl;
system("pause");
return 0;