Alright y'all I'm not sure if I'm doing this correctly or not...so any help would be great. I also plan on implementing a do while loop I just haven't yet till I get the main code to work. Thank you in advance! Here is the question from my professor:
Write a C++ program that scores a game of bowling. A game of bowling has 10 frames. The
tenth frame works in a slightly different way than the first 9. For the first 9 frames, each will consist
of 1 or 2 rolls. You will be presented with 10 pins. If you hit all 10 pins in the first roll you make a
"strike", and the frame is over. Otherwise you have a second roll to hit the remaining pins. If you hit
all remaining pins you score a "spare";otherwise you have an "open frame". The number of points
an open frame gives is simply the total number of pins you hit. A spare gives 10 points plus the
number of pins hit on your next roll (in the next frame). A strike gives 10 points plus the number of
pins hit on the next two rolls (in thenext frame, or possibly the next two frames if you hit a strike in
the nextroll). The last frame consists of 2 or 3 rolls. The way it works is as follows:
6
● 10 pins are presented
● If you hit all 10 pins, you score a strike (10 points), and 10 pins are presentedagain:
○ If you hit all 10 pins again, you score a new strike, and 10 pins are presented
again, for the last time.
● If you hit 10 pins again, you score one more strike.
● If you hit fewer than 10 pins, you score that number of pins.
○ If you hit fewer than 10 pins, you score that number of points and theremaining
pins are presented.
● If you hit all remaining pins, you score a spare (10 points).
● If you hit fewer than that, you score that many pins.
● If you hit fewer than 10 pins on the first roll, the remaining pins are presented.
○ If you hit all remaining pins, you score a spare and 10 pins are presentedagain.
● If you hit all 10 pins on the third roll, you score a strike.
● If you hit fewer than 10 pins, you score as many points as pins hit.
○ If you hit fewer than the remaining pins, you score the number of pins hit in both
rolls.
Note that the number of points in the last frame is the total number of pins hit in all rolls.
Input will be from the keyboard containing the rolls for a single game, concatenated into a single
string. Each character will be one of the following: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /, or X, where
the digits represent the number of pins knocked down, the '/ ' indicates a spare, and the 'X'
represents a strike. Note that the frames are not delimited in any way-it’s your job to figure out if a
frame has one, two, or three rolls. Assume valid input. Output the frame/total game score using the
format shown below. Finally, ask the use if he/she wishes to run the program again.
Sample Runs:
Enter bowling scores for a game: 81XX3/451/XX3/4/8
Frames
1 2 3 4 5 6 7 8 9 10
--------------------------------------------------------------------
Total Score: 170
Run again(Y/N): y
8-1 X X 3 / 4-5 1 / X X 3 / 4/8
9 32 52 66 75 95 118 138 152 170
7
Enter bowling scores for a game: XXXXXXXXXX9/
Frames
1 2 3 4 5 6 7 8 9 10
--------------------------------------------------------------------
Total Score: 289
Run again(Y/N): Y
Enter bowling scores for a game: 101/22X33X1/3/X12
Frames
1 2 3 4 5 6 7 8 9 10
--------------------------------------------------------------------
1-0 1/ 2-2 X 3-3 X 1/ 3/ X 12
1 13 17 33 39 59 72 92 105 108
Total Score: 108
Run again(Y/N): n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int frame = 10;
int roll = 0;
int scores[frame];
int Total;
string num;
num = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '/', 'X');
cout << "Enter bowling scores for a game: ";
cin >> scores[frame];
if (roll == 1)
{
if (frame > 10)
{
if (scores[frame] == 10)
{
cout << "Strike" << endl;
}
else if (scores[frame] > 10)
{
cout << scores << endl;
}
else if (roll == 2)
{
if (scores[frame] == 10)
{
cout << "Spare" << endl;
}
else if (scores[frame] > 10)
{
cout << scores << endl;
}
else if (roll == 3)
{
if (frame == 10)
{
if (scores[frame] == 10)
{
cout << "Strike" << endl;
}
else if (scores[frame] > 10)
{
cout << scores << endl;
}
}
}
}
}
}
cout << "Frames: " << endl;
cout << '1' << '\t' << '2' << '\t' << '3' << '\t' << '4' << '\t' << '5';
cout << '\t' << '6' << '\t' << '7' << '\t' << '8' << '\t' << '9' << '\t' << "10" << endl;
cout << "---------------------------------------------------------------------------" << endl;
cout << "Total score: " << Total << endl;
cin.ignore();
cin.get();
return 0;
}
|