Description
The purpose of this challenge is to use the IF statement to control program flow. This challenge simulates a very simple shopping cart.
Requirements
Feel like a challenge? Go straight to the output without looking at the step-by-step requirements!
- Declare a double variable called cost
- Declare a double variable called total
- Declare an int variable called quantity
- Declare a string variable called item
- Declare a char variable called is_gift
- Ask the user to enter a string that describes a single item to add a cart item.
- Ask the user to enter the cost of the item
- Ask the user to enter how many items are being purchased
- Ask the user if the purchase is a gift (Ask the user to enter a single character and store this in is_gift)
- Calculate the total cost of the items (multiply quantity by cost)
- Display a friendly summary message and display the total cost of the purchase. Display a reminder about gift purchases as appropriate.
Hints
- Include the <iomanip> header file. This will allow you to use various options to format your output
- It’s good practice to initialize variables to default values that make sense (for example, set quantity to 0.00)
- Include the code below before any other cout lines. The setprecision(x) will display your decimal output with x decimal places.
cout << fixed << setprecision(2);
Sample Interaction / Output
-- Welcome to AMABUYSTUFF -- What item are you buying? laptop Cost of laptop? 1399 How many are you buying? 1 Is this a gift (y/n)? y Thank you for your purchase. Please pay $1399.00. Remember that gifts can be returned or exchanged with the gift receipt before 30 days.
RUN IT AGAIN:
-- Welcome to AMABUYSTUFF -- What item are you buying? flask Cost of flask? 2.5 How many are you buying? 10 Is this a gift (y/n)? n Thank you for your purchase. Please pay $25.00
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-FLOW0001
Print Requirements