{"id":1336,"date":"2015-05-01T00:01:51","date_gmt":"2015-05-01T07:01:51","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=1336"},"modified":"2015-05-09T07:11:51","modified_gmt":"2015-05-09T14:11:51","slug":"lets-go-bowling","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=1336","title":{"rendered":"Let&#8217;s Go Bowling!"},"content":{"rendered":"<p>I went bowling the other day. Actually, I went to watch people bowl. I&#8217;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.<br \/>\n<!--more--><br \/>\nYour 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:<\/p>\n<p>1. You roll a ball down a lane to knock over 10 pins.<br \/>\n2. If you roll one ball and it knocks down all the pins, that&#8217;s 10 points and a <em>strike<\/em>.<br \/>\n3. 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.<br \/>\n4. If the score from the first and second balls equals 10. That&#8217;s a <em>spare<\/em>.<br \/>\n5. If you don&#8217;t get a strike or a spare, then the frame&#8217;s score is the total of the pins knocked down by the two balls.<\/p>\n<p>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.<\/p>\n<pre><code>| 1|5|\r\n|  6 |<\/code><\/pre>\n<p>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.<\/p>\n<p>Strikes are marked with an <code>X<\/code>:<\/p>\n<pre><code>|  |X|\r\n| 10 |<\/code><\/pre>\n<p>Spares with a <code>\/<\/code>:<\/p>\n<pre><code>| 8|\/|\r\n| 10 |<\/code><\/pre>\n<p>When a zero, or gutter ball, is rolled, the <code>-<\/code> character is used, not 0:<\/p>\n<pre><code>| 9|-|\r\n|  9 |<\/code><\/pre>\n<p>This month&#8217;s assignment is to code the simulator. Output only a single frame, not a complete game.<\/p>\n<p>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&#8217;ll become apparent as you work on the puzzle.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=1351\">Click here<\/a> to view my solution. Before you do, please consider trying to solve the puzzle on your own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simulate a bowling score for a single frame. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=1336\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1336","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1336"}],"version-history":[{"count":8,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1336\/revisions"}],"predecessor-version":[{"id":1369,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1336\/revisions\/1369"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}