I have to do the read a string, accumulate the scores, and get the average from records.dat.
The string includes name and test scores.ie John Smith 99 89 88 91.
My problem is that I can't figure out how to pull the test scores while reading the string so that I can accummulate the scores and find the average.
Here's my code so far:
Code:
#include <conio.h>
#include <iostream>
using namespace std;
#include <fstream>
#include <string>
int main(){
string str[20];
int i = 0, j = 0, last;
string str1 = "Name Score1 Score2 Score3 Score4 Average";
cout << str1 << endl;
ifstream InFile("Records.dat");
if(! InFile)
{
cout << "Error opening output file" << endl;
getch();
return -1;
}
while(! InFile.eof()){
for(int I = 0; i < 5; i++){
getline(InFile, str[i]);
cout << str[i] << endl;
}
}
InFile.close();
//To make console show
getch();
//return '0' to show that the process ran ok.
return 0;
}