Okay, I am receiving scores and names from a text file to calculate averages.
1 line contains a name, the next line will contain 3 scores separated by spaces.
Looks like this:
Tom Babidal
93 94 99
Billy Marks
13 98 56
etc
etc
My code seems to read the first 2 lines perfectly, then the other names are blank and numbers huge, so not correct at all.
Here's the code:
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
infile.open ("studentscores.txt");
getline(infile, student1);
infile >> score1 >> score2 >> score3;
getline(infile, student2);
infile >> score4 >> score5 >> score6;
getline(infile, student3);
infile >> score7 >> score8 >> score9;
infile.close();
The output of the 6 scores is:
93
94
98
2355420
1682270674
2752512
0
29729
2355440
It has the first name outputted correctly but when outputting the second and third its just empty.