I have a question in c++ , can you help me ,and tell me where is the proplem in my solution ?
The question is:
Assume that the maximum number of students in a class is 50. Write a program that reads students' names followed by their test score from a file and outputs the following:
a. class average
b. Names of all the students whose test scores are below the class average, with an appropriate message
c. Highest test score and the names of all the students having the highest score
You can use this file : in.txt
Ahmed 60.8
Mona 87.3
Ali 77.1
Mahmood 97.9
Isa 63.1
Zainab 100
MY SOLUTION :
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
int count = 0;
float avrg;
int maxIndex=0;
float sum=0;
float scores[50];
string names[50];
ifstream infile;
infile.open("in.txt");
while (!infile.eof() && (count <=50))
{
infile>>names[count]>>scores[count];
count++;
sum+=scores[count];
}
avrg= sum/count;
cout<<avrg;
if (scores[50]<avrg)
cout<<names[count];
cout<<endl;
maxIndex=scores[0];
if (scores[count]>maxIndex)
maxIndex =count;
cout <<names[count];
infile.close();
return 0;
}