Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Need help with looping this food program but keeping values
Author Message
Miko99

Posted: 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

Tony

Posted: 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.
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: