Logic - Writing input to .txt

So I'm trying to take some information that a user inputs and to then write it into a .txt file. The user would input a student ID followed by 4 quiz grades. I need to use nested loops for the input, a while loop for the outer and a for loop for the inner.

The data in the .txt should would look like:
studentID quiz1 quiz2 quiz3 quiz4
studentID quiz1 quiz2 quiz3 quiz4
etc.

My problem is I'm not sure how to structure the code. I have very few examples I'm working with to understand what I'm working with. Any help is appreciated.


There's the structure.
I need to use nested loops for the input, a while loop for the outer and a for loop for the inner.

Just go piece by piece.
Brick by brick.
There's a ton of info out there on reading data from a txt file.
Such as this very similar question:
http://www.cplusplus.com/forum/beginner/71965/
Last edited on
I still don't have a clue on how to structure this. Below is what I've come up with...it doesn't work real well. My problem is I don't know how to write this nested loop to gather the student ID then 4 quiz grades and then to ask enter 1 for more students or 0 for none...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    const int MAX_STUDENT = 1003;
    int initialID = 1000;
    int studentID;
    int quiz;
    int lastQuiz = 0;
    int quizGrade;
    
    ofstream outputFile;
    
    outputFile.open("studentGrades.txt");

    while (initialID <= MAX_STUDENT)
    {
        cout<<"Enter the student ID "<<endl;
        cin>>studentID;
        
        
        for (quiz = 0; quiz <= lastQuiz; quiz = quiz + 1)
        {
            cout<<"Enter the grade for quiz ";
            cin>>quizGrade;
        }
        
        initialID = initialID + 1;
    }
    
    outputFile.close();
    
    return 0;
}
Topic archived. No new replies allowed.