English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to write the pseudocode for this.
(1) Hot dog 1.50
(2) Fries 1.00
(3) Lemonade .75
(4) End order
You should be allowed to keep ordering from the menu until you press 4 for End order, at which point you should see a total amount due for your entire order.

So far I have this:
mainLoop()
output "1. HotDog: $1.50"
output "2. Fries: $1.00"
output "3. Lemonade: $0.75"
output "4. End of Order"
input choice
if choice = 1 (totalCost = totalCost + 1.50)
if choice = 2 (totalCost = totalCost + 1.00)
if choice = 3 (totalCost = totalCost + 0.75)
if choice = 4 (EXIT LOOP)
output "The total cost of your order is: " totalCost

Am I on the right track here? Will I be reassigning totalCost a new value each time instead of adding each cost together with the way I have it written? Thanks!

2007-12-16 08:06:07 · 2 answers · asked by Butterfli 2 in Computers & Internet Other - Computers

2 answers

I agree with Raju. Initialize totalCost = 0 before mainLoop().

Also, was/is there any specification to remove an item?
You know, I changed my mind and didn't want 4 Hot Dogs, but did want an additional Fry.
Perhaps having a minus sign at the end or at the beginning of the input?
Sorry, I couldn't help but expand on the base plan.

2007-12-17 01:53:38 · answer #1 · answered by Chris C 7 · 0 0

It wil work perfectly
initialize the total to zero before taking the choice ie in the declaration or so in order to ensure the proper addition of num

2007-12-16 16:17:32 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers