Hi guys. I just need an example of a java program that accumulates total.
I'm using Jgrasp to compile the program.
If possible, please answer the question below so I can get an example on how to do a loop program that accumulates total.
Here's the problem:
Write a program that calculates the cost of buying a burger from the CIS 103 Super Burger store. The menus has four choices to choose from:
Menu Cost ($)
Burger 2.15
Combo 1 (Fries + Drink) 3.50
Combo 2 ( Cheese + Fries + Drink) 4.85
Combo 3 (Double Cheese Burger + Fries + Drink) 5.25
The program presents a menu that allows the user to choose the desired burger combo. When the user selects an item, the program displays the cost. When the user selects option 5, the program displays the accumulated total cost.
Remember, people here will not just do your homework for you. We'll help you with your code, but people won't post it.
can you write a loop at all, of any kind? Do you know what the three loop structures are (ok, there are really four, but one is a shorthand)?
I'll give you a hint...
a 'for' loop is used when you know exactly how many times you want to loop around. The way you describe the program, you won't know this, so that one is probably out...
Never ascribe to malice that which can be adequately explained by stupidity.
Nelineli Nemu
Greenhorn
Joined: Dec 11, 2009
Posts: 3
posted
0
This is what I currently have
I am even doing it right?
A couple of general tips, though. When dealing with money, it's generally a bad idea to use floats. use some kind of int, and use the atomic unit. When dealing with American currency, store everything as pennies, and convert when you want to display.
Also, don't write 43 lines of code at a time. Many folks here will tell you to write as little as possible (sometimes even only ONE line) and then compile/test/fix until you KNOW that works...then add some more.
Jason Schindler
Greenhorn
Joined: Dec 13, 2009
Posts: 1
posted
0
Small tip...
Lines 25, 29, 33:
I think you may want
rather than
Soumil Shah
Ranch Hand
Joined: Jul 13, 2009
Posts: 54
posted
0
also you are not using curly braces for if-else conditions... as there are more than one statements within them... it should be...
One more suggestion.. instead of if-else, you could also achieve this with switch-case....