Prepare a short receipt for workshop notebooks. There are three notebooks at 275 cents each, plus a delivery charge of 125 cents. The receipt should show the item subtotal and the final amount due.
Keep each calculation in cents until it is time to display dollars. For these small whole-number amounts, multiplication and addition stay exact. For example, two pens at 150 cents each give an item total of 300 cents. Adding a 50-cent fee gives 350 cents. Only the displayed dollar amount needs a conversion.
The starter already supplies the quantities, formatting, conversion, and output statements. Two result variables are unfinished. First calculate the item subtotal. Then calculate the amount due from that subtotal and the delivery charge. This is a small dependency: the final amount should reuse the subtotal, not repeat the multiplication or use a copied answer.
The supplied static_cast<double>(...)/100 expressions convert cents for display. The formatting statement keeps two decimal places. You can focus on the arithmetic without also writing presentation code.
Check the first line before moving on: it should show the notebook cost without delivery. The amount-due line will still show its temporary zero until you complete Task 2. If the subtotal is right but the final amount is wrong, inspect the addition and the names used in totalCents; you do not need to rewrite the formatting.
subtotalCents by multiplying quantity and unitCents. The supplied first line should read Subtotal: $8.25.totalCents by adding deliveryCents to subtotalCents. The supplied second line should read Amount due: $9.50.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.
You have completed this section’s practical program. Continue to the section quiz to check the ideas behind it.