# CSCI 240 Program 2 Formatted Output, Decisions solution

\$25.00

Original Work ?

## Description

For this assignment, expand on the Shooting Percentage calculator from program 1. 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. However, unlike program 1, this variable should be an integer rather than a float/double.

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. Just like with the goals scored, this variable’s data type should also be changed to integer from float/double.

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 1. 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.

# Program Requirements

1. At the top of your C++ source code, include a documentation box that resembles the one from program 1. Make sure the Date Due and Purpose are updated to reflect the current program.
2. 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.
3. The calculated shooting percentage should be displayed with exactly 1 digit after the decimal point, including zero.
4. The number of goals scored and the number of shot attempts must be data type integer. The calculated shooting percentage must be type float or double. Make sure to use meaningful variable names.
5. Make sure and test the program with values other than the ones supplied in the sample output.
6. Hand in a copy of the source code (CPP file) 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```