In this exercise, you explore the use of integers in monetary calculations. a. Follow the instructions for

Question:

In this exercise, you explore the use of integers in monetary calculations.

a. Follow the instructions for starting C++ and opening the Advanced16.cpp file. Run the program. Enter 256.7 and 223.3 as the sales for Store 1 and Store 2, respectively. The total that appears on the computer screen (504.00) is incorrect because it is not the result of adding together the numbers 269.54 and 234.47. Press any key to stop the program.

b. Review the code contained in the Advanced16.cpp file. The #include directive tells the C++ compiler to include the contents of the iomanip file in the current program. The file contains the definition of the setprecision stream manipulator, which appears in the cout << fixed << setprecision(2) << endl; statement. The fixed stream manipulator, which is defined in the iostream file, forces a real number to display a specific number of decimal places, as specified by the setprecision stream manipulator. In this program, the output values will display with two decimal places. You will learn about the directive and both stream manipulators in Chapter 5.

c. Why does the total appear as 504.00 rather than 504.01? Hint: Change the cout << fixed << setprecision(2); statement to a comment, and then save and run the program. Enter 256.7 and 223.3 as the sales for Store 1 and Store 2, respectively.

Study the output, and then stop the program. Change the comment back to a statement.

d. Use the seven comments that appear below the main function to modify the program’s code. Why do you need to add .5 to the expressions that calculate the increased sales for both stores?

e. Save, run, and test the program to verify that it is working correctly, and then stop the program.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: