Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program that inputs three numbers representing the number o

ID: 3680865 • Letter: W

Question

Write a complete C++ program that inputs three numbers representing the number of pins knocked down by a bowler in three throws. Your program should output the computed bowling score, and check for possible input errors. For example, a throw may be in the range of 0 through 10 points, and the total of the first 2 throws must be less than or equal to 10, except when the 1st throw is a strike. The rules of bowling are that if the first throw is a strike (all 10 pins knocked down), then the score is equal to those 10 points plus the number knocked down in the next 2 rows. Thus the maximum score (3 strikes) is 30. If the 1st throw knocks down fewer than 10 pins, but the second throw knocks down the remainder of the 10 pins (a spare), then the score is those 10 points plus the number of pins knocked down on the third throw. If the first 2 throws fail to knock down all of the pins (a blow), then the score is just the total number of pins knocked down in the first 2 throws.

Explanation / Answer

Solution.cpp

#include <iostream>//input and output function header file
using namespace std;// using namespace std; tells the compiler to use the std namespace.

int notastrike (int x); //function declarations
int itsastrike (int x);
int spare (int x, int y);


int notastrike(int x)
{//function definition
int y;

cout << "Its Not a strike!, enter the number of pins you hit: ";
cin >>y;
cout << endl;

if ( x + y == 10)
{
   spare(x,y);
}
else
{
cout <<"Your score was :" << (x + y);
}

return 0;  
}

int itsastrike (int x)
{//function definition
int d,e;

   cout <<"Nice strike, please enter the number of pins you hit: ";
   cin >> d;
   cout << endl;
  
   if (d == 10)
   {
       cout << "Nice strike, please enter the number of pins you hit: ";
       cin >> e;
       cout << endl << "Your score was: " << (x+d+e);
   }
   else if (d < 10 && d >=0)
   {
       cout << " nice throw, enter the number of pins you hit: ";
       cin >> e;
       cout <<endl << "Your score was: " << (x+d+e);
   }
   else
   {
       cout << "Invalid number of pins";
   }
  
return 0;
}
  
int spare(int x, int y)
{//function definition
int z;
  
   cout <<"Nice spare, enter the number of pins you hit: ";
   cin >>z;
   cout <<" Your score is: " << (x+y+z);
  
return 0;
}

int main()
{
int x;

   cout <<"Enter the number of pins knocked over: ";
   cin >>x;
   cout << endl;
  
if (x < 10 && x >= 0)
{
   notastrike(x);
}
else if (x == 10)
{
   itsastrike(x);
}
else
{
   cout <<"Invaild number of pins knocked over";


}
return 0;
}

output

Enter the number of pins knocked over: 10

Nice strike, please enter the number of pins you hit: 10

Nice strike, please enter the number of pins you hit: 10

Your score was: 30

Enter the number of pins knocked over: 9

Its Not a strike!, enter the number of pins you hit: 1

Nice spare, enter the number of pins you hit: 3

Your score is: 13

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote