#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{
int numStudents, numQuizzes = 4, studentCount = 1, count = 1, quiz = 1, score = 0, quizCount = 1;
int stuID;
double average;
double total = 0;
ofstream outputFile;
ifstream inputFile;
cout << fixed << setprecision(2);
//Open file scores.txt
outputFile.open("quizgrades.txt");
//Get the number of students
cout << "How many students? ";
cin >> numStudents;
while (studentCount <= 3)
{
cout << "Enter Student ID: ";
cin >> stuID;
outputFile << stuID << " ";
for (quiz = 1; quiz <= numQuizzes; quiz++)
{
cout << "Enter grade for quiz " << quiz << ": ";
cin >> score;
outputFile << score << " ";
}
outputFile << endl;
studentCount++;
}
outputFile.close(); //closes Output File
inputFile.open("quizgrades.txt"); //opens Output File
studentCount = 1;
while (studentCount <= 3)
{
for (quiz = 1; quiz <= numQuizzes; quiz++)
{
inputFile >> score;
total += score;
}
average = total / 4;
inputFile >> stuID;
cout << "The average for student " << stuID << " is " << average << endl;
studentCount++;
}
inputFile.close(); //closes Input File
system("pause");
return 0;
}
How many students? 3
Enter Student ID: 1001
Enter grade for quiz 1: 100
Enter grade for quiz 2: 10
Enter grade for quiz 3: 100
Enter grade for quiz 4: 100
Enter Student ID: 1002
Enter grade for quiz 1: 100
Enter grade for quiz 2: 50
Enter grade for quiz 3: 60
Enter grade for quiz 4: 60
Enter Student ID: 1003
Enter grade for quiz 1: 30
Enter grade for quiz 2: 40
Enter grade for quiz 3: 50
Enter grade for quiz 4: 60
The average for student 100 is 302.75
The average for student 60 is 605.75
The average for student 60 is 886.50
I wasn't sure what you meant so I put it after line 55.
It seems to be working a little more accurately, but not exact.
Also, the output of the students is still wrong. Any reason why it keeps thinking the stuID is the last quiz score entered?