I am trying to write a program for a bowling score in C++ Here is what I have so far: #include int main() { const int numFrames = 10; //The number of frames is 10 const int numThrows = 21; //The number of throws is 21 int throws[numThrows]; //Input for when the number of throws is <21 int frameScores[numFrames]; //Frame scores for the frames /*Computes a score for a different amount of throws in case the number of throws is less than 21 */ for (int i = 0; i < numThrows; ++i) { //std::cout << "Please enter score for throw: " << std::endl; std::cin >> throws[i]; } /* Calculates the bowling scores for the first 9 frames */ int throwIndex = 0; for (int frame = 0; frame < 9; ++frame) { int frameScore = throws[throwIndex]; if (frameScore == 10) { //For a strike frameScore += throws[throwIndex + 1] + throws[throwIndex + 2]; ++throwIndex; } else { frameScore += throws[throwIndex + 1]; if (frameScore == 10) { //For a spare frameScore += throws[throwIndex + 2]; } throwIndex += 2; } frameScores[frame] = frameScore; } /*Calculates the bowling scores for the 10th frame */ int frameScore = throws[throwIndex] + throws[throwIndex + 1]; if (frameScore >= 10) { //For a spare or strike frameScore += throws[throwIndex + 2]; } frameScores[9] = frameScore; //Outputs the scores for all frames in game for (int frame = 0; frame < numFrames; ++frame) { std::cout << frameScores[frame]; if (frame < numFrames -1) { std::cout << " "; } } std::cout << std::endl; return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 20PE: When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making...
icon
Related questions
Question
100%

I am trying to write a program for a bowling score in C++

Here is what I have so far:

#include <iostream>

int main() {
  const int numFrames = 10; //The number of frames is 10
  const int numThrows = 21; //The number of throws is 21
  int throws[numThrows]; //Input for when the number of throws is <21
  int frameScores[numFrames]; //Frame scores for the frames

  /*Computes a score for a different amount of throws in case the     
  number of throws is less than 21 */
  for (int i = 0; i < numThrows; ++i) {
    //std::cout << "Please enter score for throw: " << std::endl;
    std::cin >> throws[i];
  }

  /* Calculates the bowling scores for the first 9 frames */
  int throwIndex = 0;
  for (int frame = 0; frame < 9; ++frame) {
    int frameScore = throws[throwIndex];
    
    if (frameScore == 10) { //For a strike
      frameScore += throws[throwIndex + 1] + throws[throwIndex + 2];
      ++throwIndex;
    }
    else {
      frameScore += throws[throwIndex + 1];
      if (frameScore == 10) { //For a spare
        frameScore += throws[throwIndex + 2];
      }
      throwIndex += 2;
    }
    frameScores[frame] = frameScore;
  }

  /*Calculates the bowling scores for the 10th frame */
  int frameScore = throws[throwIndex] + throws[throwIndex + 1];
  if (frameScore >= 10) { //For a spare or strike
    frameScore += throws[throwIndex + 2];
  }
  frameScores[9] = frameScore;

  //Outputs the scores for all frames in game
  for (int frame = 0; frame < numFrames; ++frame) {
    std::cout << frameScores[frame];
    if (frame < numFrames -1) {
      std::cout << " ";
    }
  }
  std::cout << std::endl;
  
  return 0;
}

3. zyBooks: 2.7 Bowling Scores: Bowling involves 10 frames. Each frame
starts with 10 pins. The bowler has two throws to knock all 10 pins
down. The total score is the sum of pins knocked down, with some
special rules.
Bowling - Keeping Score
• For the first 9 frames:
i. If all 10 pins are knocked down on a frame's first throw (a "strike"),
that frame's score is 10 plus the next two throws. (No second throw is
taker
ii. If all 10 pins are knocked down after a frame's second throw (a
"spare"), that frame's score is 10 plus the next throw.
iii. In the 10th frame, if the bowler's first throw is a strike, or the first two
throws yields a spare, the bowler gets a third throw. The 10th frame's
score is the the pins knocked down in the 10th frame's two or three
throws.
• Given integers represents all throws for a game, output on one line each
frame's score followed by a space (and end with a newline).
o Note that the number of throws may be as few as 11 (strikes in first 9
frames, and no strike/spare in 10th frame), or as many as 21 (2 throws
in first 9 frames, then 3 in 10th).
o For simplicity, the input will always have 21 integers. If the game
ended with fewer than 21 throws, the remaining integers will be O's
and can be ignored.
o Hints:
▪ A first for loop should just read in the 21 scores in the first array. NO
VECTORS are allowed!
■ A second for loop should fill the second array's first 9 elements
(first 9 frames). NO VECTORS are allowed!
■ Additional code should compute the 10th frame, which is unique.
Transcribed Image Text:3. zyBooks: 2.7 Bowling Scores: Bowling involves 10 frames. Each frame starts with 10 pins. The bowler has two throws to knock all 10 pins down. The total score is the sum of pins knocked down, with some special rules. Bowling - Keeping Score • For the first 9 frames: i. If all 10 pins are knocked down on a frame's first throw (a "strike"), that frame's score is 10 plus the next two throws. (No second throw is taker ii. If all 10 pins are knocked down after a frame's second throw (a "spare"), that frame's score is 10 plus the next throw. iii. In the 10th frame, if the bowler's first throw is a strike, or the first two throws yields a spare, the bowler gets a third throw. The 10th frame's score is the the pins knocked down in the 10th frame's two or three throws. • Given integers represents all throws for a game, output on one line each frame's score followed by a space (and end with a newline). o Note that the number of throws may be as few as 11 (strikes in first 9 frames, and no strike/spare in 10th frame), or as many as 21 (2 throws in first 9 frames, then 3 in 10th). o For simplicity, the input will always have 21 integers. If the game ended with fewer than 21 throws, the remaining integers will be O's and can be ignored. o Hints: ▪ A first for loop should just read in the 21 scores in the first array. NO VECTORS are allowed! ■ A second for loop should fill the second array's first 9 elements (first 9 frames). NO VECTORS are allowed! ■ Additional code should compute the 10th frame, which is unique.
Expected Program Output:
Perfect Game - every throw is a strike
10 10 10 10 10 10 10 10 10 10 10 10
30 60 90 120 150 180 210 240 270 300
Transcribed Image Text:Expected Program Output: Perfect Game - every throw is a strike 10 10 10 10 10 10 10 10 10 10 10 10 30 60 90 120 150 180 210 240 270 300
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole