Question
For this assignment, expand on the Shooting Percentage calculator from program 2. The original version of the program didn't do any error checking, which means
For this assignment, expand on the Shooting Percentage calculator from program 2. The original version of the program didn't do any error checking, which means that there was nothing to stop the user from entering a negative value for the number of goals that were scored or the number of shots that were attempted or both. So rather than assuming that the user will enter the correct value the first time, for this program, add some basic error checking to try and make sure that only good data is being used in the calculation. Note: we are doing very basic error checking in this program, we will eventually learn a better way.
As with program 1, prompt the user for the number of goals that were scored and save that value in a variable. This should still be an integer.
If the value that the user entered for the number of goals that were scored is less than 0, display an informative error message and then prompt the user to re-enter the value and save the new value in the integer variable. Note: for this assignment, we'll assume that the user will "get it right" with the new value. In future assignments, we won't make that same assumption.
Now prompt the user to enter the number of shots that were attempted and save that value in a variable. Again, this should remain an integer.
If the value that the user entered for the number of shots that were attempted is less than 0, display an informative error message and then prompt the user to re-enter the value and save the new value in the integer variable.
After all of the information has been entered and checked for validity, calculate the team's Shooting Percentage using the same basic formula from program 2. The variable that holds this value (if one was used) should remain as data type float or double. Note: keep in mind that the use of integer variables means that the formula now has integer division and that will need to be taken into consideration in order to get the correct result.
Finally, display the calculated Shooting Percentage with exactly 1 digit after the decimal point.
Processing Requirements
At the top of your C++ source code, include a documentation box that resembles the one from programs 1 and 2.This is a requirement for all of the programs in this course and this will be the last reminder in the assignment write-ups.
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 be a part of every program that is submitted for the remainder of the semester.
Make sure and test your program with values that you have calculated.
Hand in a copy of your source code using Blackboard.
Output
A few runs of the program should produce the following results:
Run 1
Enter the number of goals that were scored: 2 Enter the number of shots that were attempted: 49 The Shooting Percentage is 4.1
Run 2
Enter the number of goals that were scored: -7 Error: the number of goals must be greater than 0. Try again: 7 Enter the number of shots that were attempted: -12 Error: the number of shot attempts must be greater than 0. Try again: 32 The Shooting Percentage is 21.9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started