Let’s Go Bowling!

I went bowling the other day. Actually, I went to watch people bowl. I’m a terrible bowler, having never rolled anything higher than 148 in my life. Breaking 100 is a rare occasion. But one thing I can do well is understand how the scoring works.

Your exercise this month is to simulate a single frame for bowling and present the score in a traditional manner for that frame. Here are your objectives:

1. You roll a ball down a lane to knock over 10 pins.
2. If you roll one ball and it knocks down all the pins, that’s 10 points and a strike.
3. If you fail to knock down all 10 pins with the first ball, you roll a second ball to knock down the remainder of the pins.
4. If the score from the first and second balls equals 10. That’s a spare.
5. If you don’t get a strike or a spare, then the frame’s score is the total of the pins knocked down by the two balls.

The simulator you code displays the results in a frame, as illustrated below. The first ball appears at the top left. If necessary, the second ball appears at the top right. The score appears below.

| 1|5|
|  6 |

Above, on the first ball knocked down a single pin. Five pins were knocked down on the second ball, for a total of 6 in the frame.

Strikes are marked with an X:

|  |X|
| 10 |

Spares with a /:

| 8|/|
| 10 |

When a zero, or gutter ball, is rolled, the - character is used, not 0:

| 9|-|
|  9 |

This month’s assignment is to code the simulator. Output only a single frame, not a complete game.

I recommend that you consider breaking up repetitive chunks of code into functions. These functions may not seem obvious when you first set out to code the solution, but they’ll become apparent as you work on the puzzle.

Click here to view my solution. Before you do, please consider trying to solve the puzzle on your own.

2 thoughts on “Let’s Go Bowling!

  1. Looks like a lovely idea, but are you gonna put everything in an array? Or are you gonna make an array filled with structs?

  2. I believe your thinking and mine are the same. You’ll have to wait until next month’s Exercise to know for certain! 😀

Leave a Reply