I'm making a program to calculate student's quiz averages and class average, while using a loop to simplify it and storing the data to a file (just a .txt for now).
I'm new to c++ and this is probably the most advanced thing I've worked on so far...
My current code is:
// Grade Average calculator
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
ofstream outputFile;
ifstream inputFile;
int continueYes;
double qz, score;
string studentId;
//Open File
outputFile.open("quizav.txt");
//Continue to start...
cout << "Press 1 to add a student, Press 0 to exit.\n";
cin >> continueYes;
while (continueYes == 1){
cout << "Please Enter student ID: ";
cin >> studentId;
outputFile << studentId << " ";
for (qz = 1; qz < 5; qz++){
cout << "Enter quiz score " << qz << " ";
cin >> score;
+-score;
outputFile << " " << score << " ";
}
cout << "Press 1 to add a student, press 0 if no more.\n";
cin >> continueYes;
outputFile << " " << endl;
}
outputFile.close();
//OUT PUT FINISHED
double average;
double student, studentInfo;
inputFile.open("quizav.txt");
while (inputFile >> studentInfo){
cout << studentInfo << endl;
}
system("pause");
return 0;
}
While the top half works fine, and stores the information in a text file like so
student id score, score, score
student id score, score, score
etc.
I am not sure what to make my while and for loop on the bottom to give output roughly to my desired:
student 1's average: average student 2's average: average etc
class average:
The current While/for loop at the bottom display the right information from the file, just not in the right matter (no gaps between student IDs)
I really need it to get one line at a time, average it, and store the total to average it later.
Thank you for any help.