|
|
|
|
|
|
|
cout < The surface area is
< setprecision(3) < surfaceArea < sq. ft.
< endl;
cout < The painting cost for < endl;
cout < Red is < setw(7) < redCost < dollars
< endl;
cout < Blue is < setw(7) < blueCost < dollars
< endl;
cout < Green is < setw(7) < greenCost < dollars
< endl;
return 0;
} |
|
|
|
|
|
|
|
|
The output from the program is |
|
|
|
|
|
|
|
|
The surface area is 2.641 sq. ft.
The painting cost for
Red is 0.264 dollars
Blue is 0.396 dollars
Green is 0.475 dollars |
|
|
|
|
|
|
|
|
Testing and Debugging Hints |
|
|
|
|
|
|
|
|
1. Double-check every expression according to the precedence rules to be sure that the operations are performed in the desired order. |
|
|
|
|
|
|
|
|
2. Avoid mixing integer and floating point values in expressions. If you must mix them, consider using explicit type casts to reduce the chance of mistakes. |
|
|
|
|
|
|
|
|
3. For each assignment statement, check that the expression result has the same data type as the variable to the left of the assignment operator (=). If not, consider using an explicit type cast for clarity and safety. And remember that storing a floating point value into an int variable truncates the fractional part. |
|
|
|
|
|
|
|
|
4. For every library function you use in your program, be sure to #include the appropriate header file. |
|
|
|
|
|
|
|
|
5. Examine each call to a library function to see that you have the right number of parameters and that the data types of the parameters are correct. |
|
|
|
|
|