Nested for loop

Im trying to write a nested for loop that gets the data from an input file. The for loop will check the student and the 3 courses they are taking the 5 test from each course. The outer loop will be on students, the middle loop will be on courses and the inner loop will be on four tests.

Im stuck and I don't know how to write the for loop.

Input file
Nancy Peterson
22
510 Tumble Dr., San Gabriel, TX 57981
3
(666) 759 - 2249
492-35-5984
CS1428
80.9
90.2
98.5
89.8
97.7
CS2308
50.9
55.2
60.5
65.8
45.7
CS2308
60.9
55.2
60.5
65.8
60.7
Cole john
19
951 Moore St., San Marcos, Tx 77688
(555) 759 - 2249
555-35-5984
CS1428
80.9
90.2
98.5
89.8
97.7
CS2308
50.9
55.2
60.5
65.8
45.7
CS2308
60.9
55.2
60.5
65.8
60.7
John Doe
19
951 Moore St., San Marcos, Tx 77688
(555) 759 - 2249
555-35-5984
CS1428
80.9
90.2
98.5
89.8
97.7
CS2308
50.9
55.2
60.5
65.8
45.7
CS2308
60.9
55.2
60.5
65.8
60.7

#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;


int main()
{
string name, social, address, telephone, header;
double test, test1, test2, test3, test4, finalexam, percentage,
test5;
int age, numyears,n, course;
char letterGrade;


cout << "How many Students?";
cin >> n;


while (n >=1 ) {
n++;
}


ifstream fin;
fin.open("Input.txt");


if (fin) {
cout << "Input not opened" << endl;
return -1;


for(int n = 1; n <= 3; n++)
{
for(int course = 1; course <= 3; course++)
{
fin >> course;
}
for(int test = 1; test <= 3; test++)
{
fin >> test1;
fin >> test2;
fin >> test3;
fin >> test4;
fin >> test5;
}
}


ofstream fout;
fout.open("Output.txt");


if (fout) {
cout << "output file not opened" << endl;
return -1;


}
}
return 0;
}
Topic archived. No new replies allowed.