- Get a copy of
- If you download it, you might need to change the extension from .txt to .cpp
- On Hercules you can get it with this cp command:
cp /net/data/ftp/pub/class/110/strings/format_io.txt readdata.cpp
- Or you can use your mouse to copy and paste the program into your editor
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 Marshmallows
The output will be all wrong. Why is the product name only Fluffy? Why is the price wrong?
- 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
Fluffy Puff Marshmallows: $1.39 (with 30% discount)
- Try different inputs:
Product name: Bubble Juice
Bubble Juice: $0.69 (with 30% discount)
Product name: PS4 Pro
PS4 Pro: $349.99 (with 30% discount)
- Show your lab instructor the program output.
Copyright: Department of Computer Science, University of Regina.