- Is your Sublime Text converting Tabs to spaces? It should be. Check the Spaces menu (bottom right, in the status bar) to be sure. To ensure consistent indentation, always use the Tab key or the Sublime Text indentation shortcuts Ctrl-[, Ctrl-] (Cmd-[, Cmd-] on Mac).
(This is problem P2.11 from our textbook.) The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the books that were ordered.
Read the total book price and the number of books from the input.
Compute the tax (6% of the total book price).
Compute the shipping charge ($2 per book).
The price of the order is the sum of the total book price, the tax, and the shipping charge.
Print the price of the order.
Translate this pseudocode into a C++ program. Make sure to test your program to see that it works. Here are a few sample runs. Make sure your program produces exactly the same output as these test cases do when you give it the same inputs.
Enter the total price of the order: 45.25
Enter the number of books in the order: 3
The tax is $2.715 and the shipping cost is $6.
The total cost of the order is $45.25 + $2.715 + $6 = $53.965.
Enter the total price of the order: 1283.92
Enter the number of books in the order: 34
The tax is $77.0352 and the shipping cost is $68.
The total cost of the order is $1283.92 + $77.0352 + $68 = $1428.96.
Enter the total price of the order: 24.20
Enter the number of books in the order: 8
The tax is $1.452 and the shipping cost is $16.
The total cost of the order is $24.2 + $1.452 + $16 = $41.652.
- Notice that some of the outputs are not formatted the way we usually write currency values, that is, too many or too few decimals. Don't worry about this for now.
- Do not worry about negative prices or a negative number of books.
After you test your code, submit it. Upload a well-formatted .cpp file including correct spacing, indentation, and comments.
If you have more time, research some Sublime Text editing commands, or begin work on Programming Problem Set 1.