Hello.
I'm doing an assignment that requires the program to read data which consists of names and grade scores with each scores ending with a negative number from an input file.
It figures out an average and posts a grade for each person. The only problem that I'm having is that after going through the first name and score, the following names either come out fine or as numbers and the scores don't come out completely and it's just messy and the average always displays the average from the first reading. I tried to solve this by setting the score, average, etc = 0. Now all it does is display 0s infinitely and I have no idea how to fix it.
Any help is appreciated.
Code:
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
void main()
{
double score = double();
double sum = double ();
int count = int();
double average = double();
string fname = string();
string lname = string();
ifstream in;
in.open("E:\\in.txt");
cout << setprecision(3) << endl;
while(!in.eof())
{
in >> fname >> lname;
cout << "Your name is: " << fname << " " << lname << endl;
cout << endl;
cout << "Your scores are: ";
while(score>=0)
{
in >> score;
cout << score << " ";
if(score>=0)
{
sum = sum + score;
count++;
}
else
if(count<=1)
{
cout << endl << endl;
cout << fname << " " << lname << ", you didn't enter any scores." << endl;
cout << endl;
}
}
average = (sum / count);
if((average >= 0) && (average <= 55))
{
cout << endl << endl;
cout << fname << " " << lname << ", your average is " << average << " and your letter grade is an F." << endl;
cout << endl << endl;
}
else
if((average > 55) && (average <= 67.5))
{
cout << endl << endl;
cout << fname << " " << lname << ", your average is " << average << " and your letter grade is a D." << endl;
cout << endl << endl;
}
else
if((average > 67.5) && (average <= 80))
{
cout << endl << endl;
cout << fname << " " << lname << ", your average is " << average << " and your letter grade is a C." << endl;
cout << endl << endl;
}
else
if((average > 80) && (average <= 90))
{
cout << endl << endl;
cout << fname << " " << lname << ", your average is " << average << " and your letter grade is a B." << endl;
cout << endl << endl;
}
else
if(average > 90)
{
cout << endl << endl;
cout << fname << " " << lname << ", your average is " << average << " and your letter grade is an A." << endl;
cout << endl << endl;
}
sum = 0;
count = 0;
average = 0;
score =0;
}
}