Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with looping this food program but keeping values
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Miko99




PostPosted: Thu Jun 12, 2003 3:25 pm   Post subject: Need help with looping this food program but keeping values

How do i get this to be continuous. The user will select there choices as much as they want and the price will continue to ad up.
code:


var names : array 1 .. 17 of string := init ("Pizza", "Crispy Fries", "Hamburger", "Cheese Burger",
    "Chicken Burger", "Submarine", "Salad", "2 Cookies", "Fries", "Pasta",
    "Mashed Potatoes", "Baked Potatoes", "Pop", "Chocolate Milk",
    "Gatorade/ Powerade", "Water", "Slush Puppy")
var prices : array 1 .. 17 of real := init (2.5, 4, 3, 3.4, 2.4, 5, 3, 1, 2, 2, 1.5,
    1, 1, 1.5, 2, 1, 1.35)
var choice : array 1 .. 3 of int
var total : real := 0
var bill : real
var change : real
var f, t, l, q, d, n, p : real := 0
var choice5:string
var count:int:=0
put "Main Dishes         Prices"
loop
count:=count+1
for a : 1 .. 7
    put a, "-", names (a) : 21, prices (a) : 0 : 2
end for
get choice (1)
for a : 8 .. 12
    put a, "-", names (a) : 21, prices (a) : 0 : 2
end for
put "10-", names (10) : 20, prices (10) : 0 : 2
get choice (2)
for a : 13 .. 17
    put a, "-", names (a) : 20, prices (a) : 0 : 2
end for
get choice (3)
total := prices (choice (1)) + prices (choice (2)) + prices (choice (3))
put ("Would you like select 3 more things")
get choice5
exit when (choice5="no")
end loop
for a : 1 .. 3
    put names (choice (a)) : 23, prices (choice (a)) : 0 : 2
end for
put "--------------------------"
put "TOTAL:" : 22, total : 0 : 2
put "Enter Bill Being Used:$" ..
get bill

if bill not= 100 or bill not= 50 or bill not= 20 or bill not= 10 or
        bill not= 5 then
    put "That is not a valid Bill"
 

elsif bill = 100 or bill = 50 or bill = 20 or bill = 10 or bill = 5 then
end if


change := bill - total
cls
put "Your change is: $", change, " and you will get: "
f := change div 5
change := change - (f * 5)
t := change div 2
change := change - (t * 2)
l := change div 1
change := change - (l * 1)
q := change div .25
change := change - (q * 0.25)
d := change div .1
change := change - (d * 0.1)
n := change div .05
change := change - (n * 0.05)
p := change div .01
change := change - (p * 0.01)

put "Fives :", f
put "Toonies :", t
put "Loonies :", l
put "Quarters:", q
put "Dimes   :", d
put "Nickels :", n
put "Pennies :", p 
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jun 12, 2003 4:49 pm   Post subject: (No subject)

you put the loop around.

If you want to keep values of variables, DONT initialize (set value) inside the loop.

If you want it to be as a "brand new" run, you initialize ALL variables inside the loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: