Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <windows.h>
using namespace std;
int main()
{
int counter; //While statement counter
int numberOfTests;
int studentTestTotal;
int testScore; //Test score from file
float studentAverage;
float classAverage;
string studentName; //Student Name
string fileName;
ifstream inFile;
cout << "Please enter the filename to retrieve scores from: ";
getline(cin,fileName);
inFile.open(fileName.c_str());
if (!inFile)
{
cout << "File failed to open";
}
inFile >> numberOfTests;
while (!inFile.eof())
{
inFile >> studentName;
cout << studentName;
studentTestTotal = 0;
studentAverage = 0;
while (counter <= numberOfTests)
{
inFile >> testScore;
cout << testScore;
studentTestTotal = studentTestTotal + testScore;
counter++;
}
cout << endl;
}
inFile.close();
system("pause");
return 0;
}
This is what i have so far. Basically I need it to read in names and numbers from a file and output them. Then it needs to calculate the average for each person's score and give them a letter grade. Finally it needs to take all of the averages and calculate a class average.
1) I do not reset the counter at all... Yet it compiles and works perfectly. If i reset the counter it doesn't.... WHY!?
2) when i use inFile to input the names and scores... it puts them on a separate line. How can i get them to go on one line.
3) if i add this line
Code:
studentAverage = studentTestTotal / numberOfTests;
the program once again does not work. It is driving me crazy help is greatly appreciated