❔ Making a Vending Machine for Class!
Hey ya'll, I'm new here! I've been having some trouble with this assignment and I was hoping I could get some help.
Below is a snippet of my code so far. Below is a snippet of my code so far. Basically, I got the vending loop portion down, but I can't seem to figure out how to get the program to maintain the number of each item and then provide the total when the user ends the program.
{
Console.WriteLine(" OSU Snacks menu");
Console.WriteLine("Select 1 for Soda --> price = $" + vendingOne);
Console.WriteLine("Select 2 for Cookie --> price = $" + vendingTwo);
Console.WriteLine("Select 3 for Chips --> price = $" + vendingThree);
Console.WriteLine();
string userInput = Console.ReadLine();
double numberSelect = Convert.ToDouble(userInput);
if (numberSelect == 1)
{
Console.WriteLine("You chose soda. How many do you want?");
string quantitySelect = Console.ReadLine();
double qsoda = Convert.ToDouble(quantitySelect);
sodaQuantity += (int)qsoda;
Console.WriteLine("Press y if that is all for today");
string yesNo = Console.ReadLine();
if (yesNo == "n")
continue;
if (yesNo == "y") { Console.WriteLine("Your total is $" + sodaQuantity*vendingOne); Console.WriteLine(); break; }
if (yesNo == "y") { Console.WriteLine("Your total is $" + sodaQuantity*vendingOne); Console.WriteLine(); break; }
18 Replies
hi, i think a can help u here
so, start with putting code -
wiil be more readable
as i get, u need program which works till u press "Y" ?
Yes. How do I do what you did?
Give me one sec
so like, u started it, when u pick option, it asks to pick option again, but if u press Y, it calculates all prices and maybe prints it
$code
Posting Code Snippets
To post a code snippet type the following:
```cs
// code here
```
Notes:
- Get an example by typing
$codegif
in the chat.
- Change the language by replacing cs
with the language of your choice (for example sql
or cpp
).
- If your code is too long, you can post it to https://paste.mod.gg/ and share the link.so, i see bit from txt file, there is a bit different logic, how do u solve it, depends on what specifically u want to do
Have you learned about methods yet?
Also, my inference from your problem statement is that the user should be capable of selecting more than one item and calculate a total at the end, is that correct?
Yeah! That's what I'm having trouble with
Okay
So
Your totals shouldn't be at the top
They should be after your loop is done
Calculate the current total on the fly with each iteration and save the final calculation for after the fact.
Does that help?
I think so, I'm looking at my code and this now, thank you!
also, if u leaned switch before, use it instead of multiple if statements with same logic
so, there might be some things u don't know yet, but i think ull get it, happy to explain if need something to clarify @Aquaholic
I'm still learning quite a bit! We've really only had 5 modules of into to work with! I really do appreciate your help 🙂
I'd stick with what you know and focus on the logic then as that's like the intent of your assignment 🙂
Best of luck!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.