I cannot get the item's names to show up on the same line, and I'm not sure what I'm doing wrong. Can someone please look at my code and help me get through this part of my assignment? Also, there are some parts on the code that I haven't defined yet but that's because I'm still working on them, and they're commented out right now since I'm trying to figure out how to put the item names on the same line and can't get past it. Thanks to anyone who helps me.
Homework 3 – PROG 1003 Shopping Cart 3
Building on the program from Homework 2 - Cart.cpp.
Following the examples, we wrote in class, read an unknown number of items from the provided text file – ItemList.txt. You will use the same data types - Item name should be a string, item type should be a char, and item price should be a double.
All output to the user (on the console) should show a “$” and be rounded to two decimal places with a pleasing format – set column widths and spacing.
Assume a tax rate of 9% for standard items with a category of ‘N’
Assume a tax rate of 12.5% for special items with a category of ‘X’
Assume a tax rate of 0% for food items with a category of ‘F’
Calculate a subtotal, tax, and total.
Display the total to the user.
Allow the user to enter the amount to pay (do not assume the amount will be equal to or more than
what is due, or that the input will be a valid number). Display the change due to the user.
Create a print friendly receipt that closely matches the one provided – Receipt.txt
The point of this exercise is to learn how to use loops to handle an unknown amount of information and how to manipulation file I/O as the same time. Remember no magic numbers, follow the coding conventions, that all output should be properly formatted.
I'm using the ignore command and it's separating the text in the description field when it encounters the first space. The items I'm trying to read are these :
keyboard
22.62
N
blouse
18.17
N
plastic fork
20.16
X
credit card
14.61
F
perfume
2.76
N
playing card
2.08
N
table
5.56
N
toothbrush
16.71
F
thermometer
12.38
N
canvas
22.43
X
bottle
7.29
X
cup
14.27
X
nail file
23.07
X
slipper
5.66
N
spring
7.57
F
apple
4.28
X
food
4.66
F
chapter book
16.89
F
rusty nail
20.25
F
rubber duck
23.96
F
sharpie
20.60
X
bottle cap
13.00
X
cookie jar
7.54
X
needle
24.96
X
sailboat
23.47
F
nail clippers
11.72
X
puddle
17.89
N
white out
13.95
F
bow
15.51
F
deodorant
21.45
N
candle
14.72
F
button
7.13
X
teddies
4.75
F
bananas
15.50
N
ring
23.14
N
thread
14.42
X
rug
8.02
F
beef
10.60
X
camera
5.23
F
CD
17.86
F
door
7.61
N
twezzers
2.39
F
flag
14.26
F
house
16.84
X
stop sign
3.89
X
book
2.70
N
ipod
18.05
N
soda can
14.36
F
cat
20.93
F
coasters
2.25
X
shoe lace
22.54
N
controller
19.90
X
balloon
16.15
N
wallet
3.06
N
toilet
2.66
F
clay pot
22.15
N
scotch tape
2.33
X
soy sauce packet
2.11
X
tire swing
19.40
F
toothpaste
21.49
F
newspaper
2.15
N
seat belt
13.46
F
shirt
19.60
N
bowl
6.70
X
magnet
15.14
F
charger
15.52
N
sticky note
7.79
N
lamp shade
9.77
N
hair tie
16.88
F
blanket
9.91
X
towel
11.76
N
fridge
21.05
N
fake flowers
16.56
F
greeting card
15.56
F
knife
21.24
N
boom box
7.40
F
floor
21.74
X
pillow
15.70
X
sand paper
23.93
F
zipper
12.45
F
pool stick
21.06
X
tomato
20.03
F
fork
8.91
F
clamp
23.35
N
paint brush
21.84
N
speakers
5.53
F
glass
9.77
F
window
20.01
X
thermostat
13.17
X
truck
15.74
F
paper
1.54
F
watch
4.24
F
couch
16.46
F
bag
10.56
X
shampoo
19.98
F
air freshener
24.83
X
leg warmers
13.34
X
rubber band
19.17
X
pencil
14.22
X
street lights
19.45
F
There's about 100 of them, I can get the single words to show up just fine but the ones like "street lights" and "rubber band" I cannot get to show up on the same line. I think it has something to do with my ignore command but I'm not quite sure how to get it to show up properly on the same line, I've tried moving the ignore command and taking things out but nothing seems to get it to work.
I can get the single words to show up just fine but the ones like "street lights" and "rubber band" I cannot get to show up on the same line. I think it has something to do with my ignore command but I'm not quite sure how to get it to show up properly on the same line, I've tried moving the ignore command and taking things out but nothing seems to get it to work.
The problem is not the ignore() function call, the problem is that the extraction operator stops processing the string when it encounters a whitespace character. If you want to retrieve a string that contains spaces you should be using getline(), not the extraction operator. Looking at your input file I suggest you use getline() to read every line then use a stringstream to parse the line to convert the string to the double and the character.