I would not be doing this if it wasn't this late in the semester, but i am stuck if anyone finds it in them to help me i would be forever grateful, this assigment is due today at 11:00 AM and i just can't i've been at it for hrs and haven't gotten anywhere and this is the last assigment of the semester, so if anyone can help me her it is:
Instructions:
Please see the input file ("DrinkMachineInventory.txt"). Each time the program runs, it should read the data from the input file and then enter a loop that performs the following steps: A list of drinks is displayed on the screen. The user should be allowed to either quit the program or pick a drink. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned and subtract one from the number of that drink left in the machine. If the user selects a drink that has sold out, a message should be displayed. The loop then repeats. When the user chooses to quit the program it should display the total amount of money the machine earned.
What I can see is that your file format is bad. The fields name/price/available are separated by space. But within the first field (name) you have also a space. So getline() and >> won't work. What you can do is reading it char by char and determine if the next field starts (ispunct() / isdigit())
well I think im too much of a begginer, but besides that the concept of references confuses me so it's hard for me to think in functions. My main problem is getting the file to update the number of items left for each sodaType.
Think of references like this:
You are 'main' and someone you know wants to write something down for you.
//getting a return value.
You pass him a piece of paper.
He then returns it to you with something on it.
//pass by refference
As main, you pass by reference. so when you pass him the paper, he doesn't have to give it back to you. You already know what's written down.
When you pass by reference, what ever changes are made within a function, they are the same in the function that called it.
As for the soda available:
if sodaAvailable is greater than 0,
take away 1 soda.
else
display a message saying there are none left