Flow Control 1

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!

  1. Declare a double variable called cost
  2. Declare a double variable called total
  3. Declare an int variable called quantity
  4. Declare a string variable called item
  5. Declare a char variable called is_gift
  6. Ask the user to enter a string that describes a single item to add a cart item.
  7. Ask the user to enter the cost of the item
  8. Ask the user to enter how many items are being purchased
  9. Ask the user if the purchase is a gift (Ask the user to enter a single character and store this in is_gift)
  10. Calculate the total cost of the items (multiply quantity by cost)
  11. Display a friendly summary message and display the total cost of the purchase. Display a reminder about gift purchases as appropriate.

Hints

  1. Include the <iomanip> header file. This will allow you to use various options to format your output
  2. It’s good practice to initialize variables to default values that make sense (for example, set quantity to 0.00)
  3. 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