Hi guys. I'm having some trouble with a bowling score program i'm trying to write.
Here are the requirements:
-You should get the input and output file names from the user as input.
-The program should call 2 functions to keep track of which game has the lowest score and which game has the highest score for each set.
-The program should compute the average for each set. The output should be displayed on the console as well as sent to an output file.
Each line of the file should hold the scores for 1 set, each set consisting of 10 scores.The entire file can contain any number of lines.
The output should look like:
score1 score2 score3 score4 score5 score6 score7 score8 score9 score10
The highest score was (score here) in game (game number here)
The lowest score was (score here) in game (game number here)
The average for set (set number here) is (average here)
The only problem I have is getting the program to read each line of 10 scores as a separate string. I've tried using getline() but i'm only able to read the first string. There is an unlimited number of lines that could be in the bowling score file, so i'm guessing I use some sort of loop along with getline()? Any help is appreciated. I've been trying to figure this out for hours!
Need code, if you have any.
getline will not read the entire file at once. As its name suggests, it reads a line at a time. Getline will go up until the first newline it encounters, as far as I can say for default behavior (unlike formatted >>, which only takes up to the first whitespace). Therefore, you will have to read the file line-by-line. Chances are you'll be able to read a line, parse it into the data you require, and then read another line, rather than starting a new string variable for every line.
To avoid crashing into the end of the program, only loop while file.eof() is false, IIRC. See how that goes.