You should be able to handle all the frames generically, with a single piece of code (without repeating it 10 times).
Let's assume your input is in a string:
|
std::string line = "XXX9/X81XX9/XXX";
|
Write one function that returns just the characters relevant to frame N. For example, the characters
relevant to frame 6 are "81", frame 5 is "X81", frame 4 is "9/X", frame 10 is "XXX". Input to this function
is the frame number and the line, output is a portion of line corresponding to the given frame.
Now write a function that scores the frame. Frame 6 is 9; frame 5 is 19; frame 4 is 20; frame 10 is 30.
Input to the function is the return value from the previous function. Output is an (unsigned) integer score.
Now write a third function that takes as input the entire line, and uses the first two functions to score each
frame, adding their individual results together and returning the sum of the 10 frame scores.
Your main function can prompt the user for the line score, read it in, call the third function above and
output the result.