I'm new to programming and trying to do my first basic assignment. Unfortunately the bit I am struggling with is trying to deal with inputting the data.
The input data needs to come from a text file, with three test scores (integers) and then a name on each line. I can get my program to deal with the data fine until it comes across either a blank line, or where one of the test scores is actually letters instead of integers. Where data is bad I need the program to output a message stating it is invalid, followed by the line of bad data.
example of input data
42 44 Jones, I.
0 0 0 James, T.
39 xx 22 Wiggley, L.
41 77 78 Wilcox, P.A.
75 30 75 Zubaida, S.D.
89 0 89 Smith, S.
Therefore I'm assuming I need to do a getline() as the input, but then I'm not sure how to extract the three test scores as integers from my line of data. I need to use these scores to grade on a 1-10 scale and then do some if functions afterwards to say whether they have passed or not.
I'm probably approaching this in totally the wrong way so any help would be muc appreciated...!
First, I would suggest researching using file streams. Very easy to open, read, and write that way. After that, you could try reading in a character: streamThatYoureUsing.read(reinterpret_cast<char*>(&someChar), sizeof(char));
Then check if someChar falls between a - z or A - Z or is a space or \n then write the information accordingly. In the event that it isn't any of the above then it would follow that it must be an int, in the which case you can cast someChar as an int and write accordingly.
P.S.
Please use code tags next time you post code.