Program Help - Reading Data From .txt File

Can someone please assist? I need to read the sample data values below and produce the output at the bottom of this post. When executing the program the data repeats. Thanks in advance!

Data contained in the text file:

Jason Jones 77 87 76 82 92 96 90
Kathy Steinfield 67 77 87 88 86 89 96
Kevin Burnette 90 89 78 88 86 85 93
Josh Eley 92 87 88 89 90 91 78
Susie Lattimore 66 76 73 81 85 70 86
Stacey Smith 90 89 95 86 88 94 99
Aaron Nesmith 65 76 72 50 69 75 92

My Program thus far:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

int main (){
system("color f0");


ifstream fin;
ofstream fout;

fin.open("input3.txt");
fout.open("output3.txt");

if(!fin){
         cout<<"Input failure\n";
         system("pause");
         return 1;
         }
if(!fout){
          cout<<"Output failure\n";
         system("pause");
         return 1;
         }
string studentName;
int firstProgram, secondProgram, thirdProgram, fourthProgram, fifthProgram, firstTest, secondTest;
int programAverage, testAverage, courseAverage;
char courseGrade;
programAverage =static_cast<int>(firstProgram + secondProgram + thirdProgram + fourthProgram + fifthProgram)/(5);
testAverage =static_cast<int>(firstTest + secondTest)/(2);
courseAverage =static_cast<int>(programAverage + testAverage)/(2);

cout<<"Student Name"<<setw(10)<<"Program\nAverage"<<setw(10)<<"Test\nAverage"<<setw(10)<<"Course\nAverage"<<setw(10)<<"Letter\nGrade"<<setw(13)<<"Average\n"<<setw(10);
while(!fin.eof()){
fin>>studentName>>programAverage>>testAverage>>thirdProgram>>courseAverage>>courseGrade; 


cout<<left<<fixed<<showpoint<<setprecision(2);
fout<<left<<fixed<<showpoint<<setprecision(2);

cout<<setw(10)<<studentName<<setw(10)<<programAverage<<setw(10)<<testAverage<<setw(10)<<courseAverage<<setw(10)<<endl;
fout<<setw(10)<<studentName<<setw(10)<<programAverage<<setw(10)<<testAverage<<setw(10)<<courseAverage<<setw(10)<<endl;

if(courseAverage>=90)courseGrade= 'A';
     else if(courseAverage>=80)courseGrade= 'B';
          else if(courseAverage>=70)courseGrade= 'C';
               else if(courseAverage<=70)courseGrade= 'F';


}

         
fin.close();
fout.close();
    
    system("pause");
    return 0;
}



Student Name     Program     Test     Course     Letter
                 Average    Average   Average     Grade
Jason Jones       82.80      93.00     87.90        B
Kathy Steinfield  81.00      92.50     86.75        B
Kevin Burnette    86.20      89.00     87.60        B
Josh Eley         89.20      84.50     86.85        B
Susie Lattimore   76.20      78.00     77.40        C
Stacey Smith      89.60      96.50     93.05        A
Aaron Nesmith     66.40      83.50     74.95        C

I see that the text file contains, on each line: string string int int int int int int int.

Your code for reading in each line is this:
fin>>studentName>>programAverage>>testAverage>>thirdProgram>>courseAverage>>courseGrade;
Which looks like it will attempt to read in: string int int int int char.

That looks a bit problematic. Surely you should be trying to read in two strings and then seven ints from each line?
I understand! Thank you so much Moschops ! :-)
Topic archived. No new replies allowed.