Problem

(Desk check and program) a. For display purposes, the setprecision() manipulator allows...

(Desk check and program) a. For display purposes, the setprecision() manipulator allows rounding all outputs to the specified number of decimal places. Doing so can, however, yield seemingly incorrect results when used in financial programs that require displaying all monetary values to the nearest penny. For example, examine this program:

Clearly, the sum of the displayed numbers should be 2.99, not 3.00. The problem is that although the values in a and b have been displayed with two decimal digits, they were added internally in the program as three-digit numbers. The solution is to round the values in a and b before they’re added with the statement cƒ=ƒaƒ+ƒb;. Using the int cast, devise a method to round the values in the variables a and b to the nearest hundredth (penny value) before they’re added.

b. Include the method you devised for Exercise 15a in a working program that produces the following display:

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 3.3