Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview For this assignment, expand (again) on the Shooting Percentage calculator from programs 2 and 3. This time the program will do better error checking

Overview

For this assignment, expand (again) on the Shooting Percentage calculator from programs 2 and 3. This time the program will do better error checking than in program 3 and it will have the ability to calculate the Shooting Percentage through multiple games.

Processing

As noted above, there are two changes that need to be made for this program. The first is to do better error checking for both the number of goals scored and the number of shot attempts than what was used in program 3. Instead of using a decision statement, change the error checking so that it uses one of the three loops that has been discussed in lecture. The choice of loop is up to you unless otherwise specified by your instructor.

The use of a loop for the error checking rather than a decision statement will allow us to make sure that user of the program really does "get it right" when they are entering the input rather than we, as programmers, assuming that they will "get it right."

The second change that needs to made for this program is to make it so that it can calculate the Shooting Percentage through multiple games. To do this, three things will need to be added. The first is that the code that has already been written should be placed inside of a loop that executes as long as there is data to be entered.

To determine if there is more data to be entered, the user should be asked, "Is there more data?". An answer of "y" indicates there is more data. Anything else, including "Y", indicates there is no more data. (Notice the double quotes around the "y" - this means that a string variable should be used for this value.)

The second thing to be added (it must go inside of the loop) is to make a small change to the formula to calculate the shooting percentage. The values that the user is entering are the number of goals and shot attempts for ONE game. The calculation for this program should be for MULTIPLE games. This means that the program will need to keep track of the total number of goals that have been scored and the total number of shots that have been attempted. The two totals will be what is used to calculate the shooting percentage.

As with programs 2 and 3, display the shooting percentage. However, the display should include the number of games that have been played. This is the third thing to be added (again, inside of the loop).

Once the user has indicated that there is no more data, the program should end.

Processing Requirements

Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. This will also be a part of every program that is submitted for the remainder of the semester.

The float/double values should be displayed with exactly 1 digit after the decimal point.

Make sure and test your program with values that you have calculated.

Hand in a copy of your source code (the CPP file) using Blackboard.

Output

Enter the number of goals that were scored: 5 Enter the number of shots that were attempted: 34 The Team Shooting Percentage after 1 game(s) is 14.7 Is there more data? (y or n): y Enter the number of goals that were scored: 1 Enter the number of shots that were attempted: 53 The Team Shooting Percentage after 2 game(s) is 6.9 Is there more data? (y or n): y Enter the number of goals that were scored: 2 Enter the number of shots that were attempted: 49 The Team Shooting Percentage after 3 game(s) is 5.9 Is there more data? (y or n): y Enter the number of goals that were scored: -7 Error: the number of goals must be greater than 0. Try again: -1 Error: the number of goals must be greater than 0. Try again: -5 Error: the number of goals must be greater than 0. Try again: 7 Enter the number of shots that were attempted: 32 The Team Shooting Percentage after 4 game(s) is 8.9 Is there more data? (y or n): y Enter the number of goals that were scored: 0 Enter the number of shots that were attempted: 18 The Team Shooting Percentage after 5 game(s) is 8.1 Is there more data? (y or n): n 

Extra Credit

For up to 5 points of extra credit, add code that will display the change in shooting percentage from when the program begins to when the program ends.

The value that is displayed should have a descriptive label that includes the total number of games that have been played. The shooting percentage should have exactly one digit after the decimal point and should have a percent sign after the last digit.

Note about extra credit: the points will ONLY be awarded if the required portions of the assignment work correctly. In other words, don't take short cuts in the rest of the program because it is assumed that 5 extra points will be awarded.

Extra Credit Output

Enter the number of goals that were scored: 5 Enter the number of shots that were attempted: 34 The Team Shooting Percentage after 1 game(s) is 14.7 Is there more data? (y or n): y Enter the number of goals that were scored: 1 Enter the number of shots that were attempted: 53 The Team Shooting Percentage after 2 game(s) is 6.9 Is there more data? (y or n): y Enter the number of goals that were scored: 2 Enter the number of shots that were attempted: 49 The Team Shooting Percentage after 3 game(s) is 5.9 Is there more data? (y or n): y Enter the number of goals that were scored: -7 Error: the number of goals must be greater than 0. Try again: -1 Error: the number of goals must be greater than 0. Try again: -5 Error: the number of goals must be greater than 0. Try again: 7 Enter the number of shots that were attempted: 32 The Team Shooting Percentage after 4 game(s) is 8.9 Is there more data? (y or n): y Enter the number of goals that were scored: 0 Enter the number of shots that were attempted: 18 The Team Shooting Percentage after 5 game(s) is 8.1 Is there more data? (y or n): n The change in Team shooting percentage after 5 game(s) is -6.6% 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the minimal group paradigm.

Answered: 1 week ago

Question

2. What are your challenges in the creative process?

Answered: 1 week ago