----------------------------------- Hunter007 Wed Jan 14, 2004 6:27 pm Looping/Valid/Invalid Input... ----------------------------------- I've been working on a lot of different progs at the same time (school) and I seem to have gotten confused. This program here is supposed to calculate any amount of pizzas(any size) with any number of toppings. No tax is needed. I think it calculates one order at a time now. :? I;m posting my code, hoping someone can help me out. const smallpiz : real := 6.00 const largepiz : real := 8.00 const smalltop : real := 0.75 const largetop : real := 1.25 var pizza : string var numtop : real var cost : real := 0 var topcost : real:=0 var reply : string (1) var totalcost : real:=0 var subtotal : real:=0 loop put "Press any key to continue or 'q' to quit..." put "" getch (reply) exit when reply = "q" or reply = "Q" loop put "**When finished type in 'none' as pizza size.**" put"" put "Small or large pizza? " .. get pizza put "" if pizza = "none" then exit end if put "Number of toppings: " .. get numtop if pizza = "small" then topcost := numtop * smalltop cost := smallpiz + topcost elsif pizza = "large" then topcost := numtop * largetop cost := largepiz + topcost end if cls end loop totalcost := totalcost + cost put "The cost of your pizza is $", totalcost : 2 : 2, "." delay (2500) cls cost := 0 topcost := 0 totalcost:=0 end loop ----------------------------------- poly Wed Jan 14, 2004 7:47 pm ----------------------------------- I see what your error is and its a very simple one, just have to move a line up. Here I posted the code below, you can see what I moved to fix this error, I made comment: const smallpiz : real := 6.00 const largepiz : real := 8.00 const smalltop : real := 0.75 const largetop : real := 1.25 var pizza : string var numtop : real var cost : real := 0 var topcost : real := 0 var reply : string (1) var totalcost : real := 0 var subtotal : real := 0 loop put "Press any key to continue or 'q' to quit..." put "" getch (reply) exit when reply = "q" or reply = "Q" loop put "**When finished type in 'none' as pizza size.**" put "" put "Small or large pizza? " .. get pizza put "" if pizza = "none" then exit end if put "Number of toppings: " .. get numtop if pizza = "small" then topcost := numtop * smalltop cost := smallpiz + topcost elsif pizza = "large" then topcost := numtop * largetop cost := largepiz + topcost end if totalcost := totalcost + cost % I JUST MOVED THIS LINE BEFORE THE CLS cls end loop put "The cost of your pizza is $", totalcost : 2 : 2, "." delay (2500) cls cost := 0 topcost := 0 totalcost := 0 end loop the formula " totalcost := totalcost + cost " was after the CLS, so when it was time to tally it all up the CLS would just clear all vars. So I just moved it above the CLS and presto! ----------------------------------- Thuged_Out_G Thu Jan 15, 2004 10:36 am ----------------------------------- cls only clears the screen, it doesnt clear variables ----------------------------------- DanShadow Thu Jan 15, 2004 1:47 pm ----------------------------------- No, no, no...poly is right, and he wasnt clearing variables. cls end loop totalcost := totalcost + cost totalcost := totalcost + cost % I JUST MOVED THIS LINE BEFORE THE CLS cls end loop See, poly moved the totalcost calculator from outside the loop, to inside above the cls...he wasnt try to stop cls from clearing variables or anything. :wink: ----------------------------------- Thuged_Out_G Thu Jan 15, 2004 2:52 pm ----------------------------------- thats just the mesasge i got from CLS would just clear all vars