Nested for loop. Help Please!!!

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;
}

Last edited on
dbarclay100, instead of double posting
http://www.cplusplus.com/forum/general/250521/
you'd better read here:
Welcome -- read before posting!: http://www.cplusplus.com/forum/beginner/1/
How to use tags: http://www.cplusplus.com/articles/z13hAqkS/
How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

To cut it short:
- you should decide what you want to do with your data while you read them (I think you want to save them into a container, but that's not the only option);
- do you know about structs?
- to manage a name|space|surname combination, you need either two std::strings or std::getline();
- every loop in your code should read some data:
outer loop
    name surname
    address
    ...
    inner loop
        course id
        inner-inner loop
            mark


BTW, are you sure about those data? At first sight, they look untidy.
Last edited on
Topic archived. No new replies allowed.