Question

In: Computer Science

Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...

Programming language: C++  

suggested software: Code::Blocks

Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward.

Submit your design, code, and execution result

via file, if possible

Solutions

Expert Solution

The design/algorithm of the given problem is as follows:-

start
totA=0,totB=0
print "Enter score of both team during each innings:"
for i=1 to 9 do
print "Inning "+i+":"
print "Team A: "
input A
print "Team B: "
input B
totA=totA+A
totB=totB+B
end-for
print "Final score of basketball game:"
print "Team A\tTeam B"
print totA+"\t"+totB
stop

The C++ code is as follows:-

#include<iostream>
using namespace std;
int main()
{
int A,B,totA=0,totB=0;
cout<<"Enter score of both team during each innings:"<<endl;
for(int i=1;i<=9;i++)
{
cout<<"Inning "<<i<<":"<<endl;
cout<<"Team A: ";
cin>>A;
cout<<"Team B: ";
cin>>B;
totA+=A;
totB+=B;
}
cout<<"Final score of basketball game:"<<endl;
cout<<"Team A\tTeam B"<<endl;
cout<<totA<<"\t"<<totB<<endl;
return 0;
}

The output of the above code is as follows:-

Enter score of both team during each innings:
Inning 1:
Team A: 12
Team B: 21
Inning 2:
Team A: 23
Team B: 20
Inning 3:
Team A: 16
Team B: 23
Inning 4:
Team A: 28
Team B: 25
Inning 5:
Team A: 28
Team B: 22
Inning 6:
Team A: 21
Team B: 16
Inning 7:
Team A: 25
Team B: 20
Inning 8:
Team A: 26
Team B: 28
Inning 9:
Team A: 18
Team B: 19
Final score of basketball game:
Team A   Team B
197   194

The screenshot of the above code is as follows:-


Related Solutions

**C++ Programming Language** a program that computes the average of a collection of numbers and then...
**C++ Programming Language** a program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. The objective of this assignment is to select a language that you have never used before and modify the program from the text so that it outputs the number of A's, B's, C's, D's and F's. An A grade is any score that is at least 20% greater than the average. The...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold by three vendors in four different zones. Is required:  Request the sale amount of each seller by zone, the values must be entered through the keyboard and validate that it does not accept negative numbers.  Menu that requests the operation to be carried out. In case of entering an invalid data, send an error message and request the operation again.  Option...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained by 3 amounts in five different zones. Is required: + Request the total of votes by zone of each candidate, the values must be entered on the keyboard and validate that it does not accept negative numbers + Menu that requests the operation to be performed, in case of entering an invalid data send an error message and request the operation again + Option...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X,...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X, if X is greater than 1 and X is less than 100. Put the inline function in a main program that reads X from the keyboard, calls the function, and then outputs the result. 2. Show an empty statement and detail what it does? 3. A collection of predefined functions is called a Database                    C) Subroutine                       E) None of these Library                       D) Directive 4....
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a code in C or C++ programming language that generates the hexadecimal values in Table...
Write a code in C or C++ programming language that generates the hexadecimal values in Table 6-2 in the same format. Table 6-2 Hexadecimal text file specifying the contents of a 4 × 4 multiplier ROM. 00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 20: 00 02 04 06 08 0A 0C 0E 10...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during their candy bar fundraiser using the following data: 12 bars per case. The candy was sold for $1.00 per bar. Each case cost $8.00. They are required to give the student government association 10% of their earnings. The program should ask the user how many bars were sold. The program should calculate and display the SGA proceed's, the Cheer team's proceeds, and the appropriate...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT