IO exercise:
- Use
ex2_format_io.cpp
in the Visual Studio project or copy the following code into your IDE:
The purpose of the program is to practice the getline and output formatting functions.
- Examine the code and test the program with this input:
Fluffy Puff MarshmallowsThe output will be all wrong. Why is the product name only Fluffy? Why is the price wrong?
1.99
- Read the whole product name as one string.
- Format the price with discount so it always shows exactly two decimal places.
- Your final result should look like this:
Product name: Fluffy Puff Marshmallows
Price: $1.99
Fluffy Puff Marshmallows: $1.39 (with 30% discount)
- Try different inputs:
Product name: Bubble Juice
Price: $0.99
Bubble Juice: $0.69 (with 30% discount)
Product name: PS5
Price: $499.99
PS5: $349.99 (with 30% discount)
When you are done:
- Take a screenshot of your IDE and console window after running the program three times (with the three inputs shown above).
- For this exercise, you will have:
ex2_format_io.cpp
. - If you have completed everything, congratulations! Please upload your .cpp files and the screenshots to URCourses.