Computer Science Canada Need help with a food program in turing

 Author: Miko99 [ Tue May 27, 2003 7:02 pm ] Post subject: Need help with a food program in turing Ok. I have been struggling with this. I need to make a program that allows the user to buy their lunch. They pick from a menu what they want and then the computer spits out what their Bill is. They type in the size of the bill they will use (\$50,\$20,\$10,\$5 etc.) and the computer calculates how much change you will get. It tells the exact number of quarters, dollars, toonies, dimes, nickles, penny's, 5's, 10's (you get the point lol) that you will need. I need help with this. PLEASE HELP!!

 Author: Asok [ Tue May 27, 2003 7:04 pm ] Post subject: ok general rule of thumb. If your asking for help we have to assume you've done some work on it as such post your code. No one here is going to write the entire program for you. On top of that, this is probably an assignment, handing someone elses work in is considered plagerism and will not be tollerated.

 Author: Tony [ Tue May 27, 2003 7:10 pm ] Post subject: some sujestions though... use arrays to store your lists of food items and another array for prices... have a variable to count the total... as for the change, its same as converting numbers to binary... find the largest change(or even bill) you can fit in the remainder of the change to give out, untill you get down to pennies. such as for \$1.67 its \$1, 2 \$0.25, \$0.1, \$0.05, 2 \$0.01

 Author: Miko99 [ Tue May 27, 2003 7:12 pm ] Post subject: Actually i just cant get it to display the change part.

 Author: void [ Tue May 27, 2003 8:07 pm ] Post subject: easy...use mod..what does the bill minus price equal?...take that...mod it by 2 (toonies), then subtract that number times two from the change, then mod it by 1 and repeat until you reach 0.01...then you will be done...understand?

Author:  Miko99 [ Tue May 27, 2003 8:19 pm ]
Post subject:

Heres my code so far. Please correct because i cant figure it out!

 code: var tens,tens1,nickles,nickles1,fives,fives1,toonies,toonies1,loonies,loonies1,quarters,quarters1,dimes,dimes1,pennys,pennys1:int var main:string var A:real:=300 var B:int:=340 var C:int:=240 var D:int:=500 var E:int:=300 var side:string var F:int:=100 var G:int:=200 var H:int:=200 var I:int:=150 var J:int:=100 var drink:string var K,N:int:=100 var L:int:=150 var M:int:=200 var O:int:=135 var total,choice,change:int   loop put "Please Select one of the following main courses" put "A = Hamburger" put "B = Cheeseburger" put "C = Chicken Burger" put "D = Submarine" put "E = Salad" get main exit when main = A or main = B or main =  or main = D or main = E end loop loop put "please select one of the following side dishes" put "F = 2 Cookies" put "G = Fries" put "H = Pasta" put "I = Mashed Potato's" put "J = Baked Potatoes" get side exit when side = F or side = G or side = H or side = I or side = J end loop loop put "please select a drink" put "K = Pop" put "L = Chocolate Milk" put "M = Gatoraid/Poweraid" put "N = Bottled Water" put "O = Slush Puppy" get drink exit when drink = K or drink = L or drink = M or drink = N or drink = O end loop total:=drink+side+main put "Your total comes to ",total put "What bill will you use to pay for this?" get choice change:=choice-total if (change>1000) then loop tens1:=change-1000 tens:=tens+tens1 change:=change-1000 exit when change < 1000 end loop put "you will need ",tens," tens" end if if (change>500) then loop fives1:=change-500 fives:=fives+fives1 change:=change-500 exit when change < 500 end loop put "you will need ",fives," fives" end if if (change>200) then loop toonies1:=change-200 toonies:=toonies+toonies1 change:=change-200 exit when change < 200 end loop put "You will need ",toonies," toonies" end if if(change>100) then loop loonies1:=change-100 loonies:=loonies+loonies1 change:=change-100 exit when change < 100 end loop put "You will need ",loonies," loonies" end if if (change>25) then loop quarters1:=change-25 change:=change-25 exit when change < 25 end loop put "You will need ",quarters," quarters" end if if (change>10) then loop dimes1:=change-10 dimes:=dimes+dimes1 change:=change-10 exit when change < 10 end loop end if if (change>5) then loop nickles1:=change-5 nickles:=nickles+nickles1 change:=change-5 exit when change < 5 end loop put "You will need ",nickles," nickles" end if if (change > 1) then loop pennys1:=change-1 pennys:=pennys+pennys1 change:=change-1 exit when change < 1 end loop put "You will need ",pennys," pennys" end if

 Author: void [ Tue May 27, 2003 8:34 pm ] Post subject: why do the foods cost hundreds??!?!?!?!?

 Author: Tony [ Tue May 27, 2003 8:35 pm ] Post subject: maybe he's from russia

 Author: void [ Tue May 27, 2003 8:40 pm ] Post subject: lolz...i dont think russia uses toonies....

 Author: Tony [ Tue May 27, 2003 8:43 pm ] Post subject: no, its the exchange rate... its something like \$1 = 20 rubles... so a 100 is \$5... hmm... you can buy a submarine for \$25... ya, he must be from russia

 Author: JSBN [ Tue May 27, 2003 8:44 pm ] Post subject: That better be the best damn burger & cookies that i ever had

 Author: void [ Tue May 27, 2003 8:51 pm ] Post subject: LMFAO how do u use strint?

Author:  Tony [ Tue May 27, 2003 9:00 pm ]
Post subject:

 code: var number:int var word:string := "1" number := strint(word)

 Author: Miko99 [ Tue May 27, 2003 9:04 pm ] Post subject: i know this is all funny but it really doesn't help. lol. the food will be divided by 100 when i print the total out.

 Author: Homer_simpson [ Tue May 27, 2003 9:05 pm ] Post subject: hehe i remeber doing the exact program a long time ago(5-6 years ago) but u wouldn't pick from any menu... u'd enter the price and the bill...i did it with turbo pascal(Oh memories =Ãž)

 Author: void [ Tue May 27, 2003 9:09 pm ] Post subject: long live pascal

Author:  void [ Tue May 27, 2003 9:22 pm ]
Post subject:

i think this is what your looking for mr.im too lazy to try...
 code: var names : array 1 .. 15 of string := init ("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 .. 15 of real := init (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 t, l, q, d, n, p : real := 0 put "Main Dishes         Prices" for a : 1 .. 5     put a, "-", names (a) : 21, prices (a) : 0 : 2 end for get choice (1) for a : 6 .. 9     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 : 11 .. 15     put a, "-", names (a) : 20, prices (a) : 0 : 2 end for get choice (3) total := prices (choice (1)) + prices (choice (2)) + prices (choice (3)) 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 = 100 or bill = 50 or bill = 20 or bill = 10 or bill = 5 then elsif bill not= 100 or bill not= 50 or bill not= 20 or bill not= 10 or         bill not= 5 then     put "YOU IDIOT THAT IS NOT A BILL"     put "TERMINATING PROGRAM DUE TO STUPIDITY" end if change := bill - total cls 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 "Toonies :", t put "Loonies :", l put "Quarters:", q put "Dimes   :", d put "Nickels :", n put "Pennies :", p

if that doesnt work....your loss not mine

 Author: Miko99 [ Tue May 27, 2003 10:10 pm ] Post subject: awwww u hurt my feelings....for a second...until i realise its true. and by the way, i dont like your driving so i plan on staying off my lawn! LoL

 Author: void [ Wed May 28, 2003 7:49 am ] Post subject: dont try to get on my good side...you ruined our perfectly fine pointless topic...

Author:  Miko99 [ Tue Jun 03, 2003 9:53 am ]
Post subject:

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.

My code so far thanks to void:
 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

Author:  w0lv3rin3 [ Tue Jun 03, 2003 8:41 pm ]
Post subject:

I'm looking @ this code, what does 21 and 0 : 2 do witin the code

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

also here

what does 23, 0 : 2, and in put "TOTAL:" : 22, total : 0 : 2, where u see 22, total : 0 : 2, whats those numbers their for?

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

 Author: Tony [ Tue Jun 03, 2003 9:15 pm ] Post subject: alignment... :number after a string sets the minimum size string has to be and adds spaces to output to match that number, so you can have preaty looking columns... second :number sets presision of real values (desimal places)

 Author: Miko99 [ Wed Jun 04, 2003 1:01 pm ] Post subject: Well how do i get that code to loop over and over and the total continusely adds up and is displayed at the end, with the exact coins they will get back.

 Author: krishon [ Wed Jun 04, 2003 1:36 pm ] Post subject: just put a loop around everything

 Author: Miko99 [ Mon Jun 09, 2003 8:02 am ] Post subject: Tried it, and id didn't work.

 Author: Andy [ Mon Jun 09, 2003 8:06 am ] Post subject: turing's mod is screwed up, there is a rounding error

Author:  Grey_Wolf [ Mon Jun 09, 2003 3:42 pm ]
Post subject:

 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

This code should loop it forever although i would suggest asking the user if they wish to continue.

 Author: Miko99 [ Wed Jun 11, 2003 9:22 am ] Post subject: That code doesn't keep everything the user selects in memory. I need it to keep everything. so i fi select 6 things, then i get charged for 6 things.

 Author: Miko99 [ Thu Jun 12, 2003 7:48 am ] Post subject: can someone please tell me how to get the food program to loop and continuesly add up the prices no matter how much food i select.

 :