Build a ticket quote for a community event. The base price depends on age, and membership determines a separate discount. Keeping these decisions separate makes the price rule easier to check.
Use these event rules:
| Visitor | Base price |
|---|---|
| Under 18 | 600 cents |
| 18 or older | 1000 cents |
Members receive a 100-cent discount. Non-members receive no discount. The supplied visitor is 16 years old and is a member. These are fixed facts in this small program; there is no keyboard input to collect.
First choose the base price with if/else. Next choose the discount with the conditional operator. Finally subtract the discount from the base. You do not need nested decisions: the age decision and membership decision answer different questions.
The starter includes one output line for each result. These are useful checkpoints, not extra statements you need to write. All monetary calculations stay in integer cents. The final line converts to dollars and uses the two-decimal formatting from the preceding section.
There are two kinds of edit here. For Task 1, leave the declaration of baseCents and insert the decision below it. For Tasks 2 and 3, replace the zeros in the existing declarations. This order matters: the age decision must set the base price before the final calculation reads it.
if/else to assign baseCents: 600 when age < 18, or 1000 otherwise. Expect Base cents: 600.discountCents with member ? 100 : 0. Expect Discount cents: 100.finalCents by subtracting discountCents from baseCents. Expect Ticket: $5.00.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.