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

Username:   Password: 
 RegisterRegister   
 Turing Menu
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
IsStickel




PostPosted: Mon Apr 30, 2012 2:24 pm   Post subject: Turing Menu

Hi, I am trying to make a code using arrays that will allow a user to choose multiple items from a menu and then get a receipt displaying what they ordered, the quantity of each item they ordered, the price of each item they ordered, 13% tax, the subtotal before tax, then the total, and a 10% commission if the subtotal is over $10. I really need help and FAST! I have most of the program done but it crashes when you get to the receipt. Any ideas?


%declare variables
var fontID : int
var winID1 : int
var winID2 : int
var winID3 : int
var picID : int
var picID2 : int
var picID3 : int
var picID4 : int
var picID5 : int
var picID6 : int
var picID7 : int
var picID8 : int
var picID9 : int
var picID10 : int
var picID11 : int
var picID12 : int
var picID13 : int
var picID14 : int
var picID15 : int
var picID16 : int
var picID17 : int
var picID18 : int
var leave := false
var Item : array 1 .. 10 of string (30)
var Quantity : array 1 .. 10 of int
var Price : array 1 .. 10 of real
var Price_New : array 1 .. 10 of real
var Item_Total : array 1 .. 10 of real
var Price_String : array 1 .. 10 of string (20)
var Quantity_String : array 1 .. 10 of string (20)
var ItemTotal_String : array 1 .. 10 of string (20)
var Selection : string
var Sub_Total : real := 0
var Total : real
var hst : real
var Gratuity : real
var x : int := 0

% open window 1
winID1 := Window.Open ("position:top;center,graphics:641;380")

% delcare picture files
picID := Pic.FileNew ("Intro.jpg")
picID2 := Pic.FileNew ("Intro2.jpg")
picID3 := Pic.FileNew ("Menu Item 1.jpg")
picID4 := Pic.FileNew ("Menu Item 2.jpg")
picID5 := Pic.FileNew ("Menu Item 3.jpg")
picID6 := Pic.FileNew ("Menu Item 4.jpg")
picID7 := Pic.FileNew ("Menu Item 5.jpg")
picID8 := Pic.FileNew ("Menu Item 6.jpg")
picID9 := Pic.FileNew ("Bacon.jpg")
picID10 := Pic.FileNew ("Homefries.jpg")
picID11 := Pic.FileNew ("Benedict Eggs.jpg")
picID12 := Pic.FileNew ("Orange Juice.jpg")
picID13 := Pic.FileNew ("Lemonade.jpg")
picID14 := Pic.FileNew ("Chocolate Milk.gif")
picID15 := Pic.FileNew ("Milk.jpg")
picID16 := Pic.FileNew ("Hot Chocolate.bmp")
picID17 := Pic.FileNew ("Coffee.jpg")
picID18 := Pic.FileNew ("Background2.gif")

setscreen ("graphics")

% splashscreen using pictures
%Pic.DrawSpecial (picID, -2, -67, picCopy, picFadeIn, 1000)
%delay (1000)
%Pic.Draw (picID2, -2, -67, picCopy)
%delay (1000)
%Pic.Draw (picID, -2, -67, picCopy)
%delay (1000)
%Pic.Draw (picID2, -2, -67, picCopy)
%delay (1000)
%Pic.Draw (picID, -2, -67, picCopy)
%delay (1000)
%Pic.Draw (picID2, -2, -67, picCopy)
%delay (1000)

% close window 1
Window.Close (winID1)

% open window 2
winID2 := Window.Open ("position:top;center,graphics:641;680")

loop
x := x + 1
loop
cls
Pic.Draw (picID18, -20, 100, picUnderMerge)

fontID := Font.New ("Broadway:20")
Font.Draw ("Meals", 270, 630, fontID, black)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("1. Farmer's Breakfast - ", 23, 600, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $8.99", 160, 600, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Two eggs, three bacon strips and a pork sausage, served with toast and jam. ", 25, 580, fontID, darkgrey)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("2. Sam-I-Am Breakfast -", 23, 555, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $5.99", 166, 555, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Two eggs and three slices of ham, served with toast and jam. ", 25, 535, fontID, darkgrey)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("3. Lumberjack Breakfast -", 23, 510, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $10.99", 167, 510, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Three pancakes, sausage, bacon, and hash brown. Topped with maple syrup and", 25, 490, fontID, darkgrey)
fontID := Font.New ("Georgina:10")
Font.Draw ("French Toast on the side. ", 25, 473, fontID, darkgrey)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("4. Egg-tastic Breakfast -", 23, 450, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $8.99", 167, 450, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Three eggs, a hearty serving of bacon, and hash brown on the side.", 25, 430, fontID, darkgrey)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("5. Early Bird Breakfast -", 23, 405, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $9.99", 167, 405, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Two eggs, crispy bacon strips, sausage, and a hash brown, served with toast and", 25, 385, fontID, darkgrey)
fontID := Font.New ("Georgina:10")
Font.Draw ("jam.", 25, 370, fontID, darkgrey)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("6. French Toast Breakfast -", 23, 346, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $6.99", 185, 346, fontID, red)
fontID := Font.New ("Georgina:10")
Font.Draw ("Three slices of French Toast, served with maple syrup and egg.", 25, 326, fontID, darkgrey)



fontID := Font.New ("Broadway:20")
Font.Draw (" Sides Drinks", 80, 250, fontID, black)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("7. Bacon or sausage (3 pcs.) - 10. Orange Juice - ", 23, 220, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $2.49 Price: $1.49", 185, 220, fontID, red)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("8. Homefries - 11. Lemonade - ", 23, 200, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $2.49 Price: $1.49", 100, 200, fontID, red)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("9. Two Benedict Eggs - 12. Chocolate Milk - ", 23, 180, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $3.49 Price: $1.69", 100, 180, fontID, red)


fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("13. Milk -", 420, 160, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $1.69", 470, 160, fontID, red)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("14. Hot Chocolate -", 420, 140, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $1.69", 530, 140, fontID, red)

fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw ("15. Coffee -", 420, 120, fontID, black)
fontID := Font.New ("Adobe Caslon Pro Bold:11")
Font.Draw (" Price: $1.29", 490, 120, fontID, red)

fontID := Font.New ("Bodoni MT Black:15")
Font.Draw ("*Enter 16 to get your bill*", 23, 130, fontID, black)
put ""

locatexy (0, 100)


put ""
put "Please enter the selection for what you'd like to order"
put "Order Number: " ..
get Selection
put ""

x := x + 1

case Selection of

label "1" :
Item (x) := "Farmer's Breakfast"
Price (x) := 8.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID3, 0, 0, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "2" :
Item (x) := "Sam-I-Am Breakfast"
Price (x) := 5.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID7, 55, -10, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "3" :
Item (x) := "Lumberjack Breakfast"
Price (x) := 10.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID5, 10, 0, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "4" :
Item (x) := "Egg-tastic Breakfast"
Price (x) := 8.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID3, 0, -70, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "5" :
Item (x) := "Early Bird Breakfast"
Price (x) := 9.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID7, 55, -50, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "6" :
Item (x) := "French Toast Breakfast"
Price (x) := 6.99
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID8, 70, -60, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "7" :
Item (x) := "Bacon or sausage (3 pcs.)"
Price (x) := 2.49
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID9, 70, -60, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "8" :
Item (x) := "Homefries"
Price (x) := 2.49
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID10, 70, -40, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "9" :
Item (x) := "Two Benedict Eggs"
Price (x) := 3.49
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID11, 90, -70, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "10" :
Item (x) := "Orange Juice"
Price (x) := 1.49
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID12, 95, -15, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "11" :
Item (x) := "Lemonade"
Price (x) := 1.49
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID13, 160, -40, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "12" :
Item (x) := "Chocolate Milk"
Price (x) := 1.69
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID14, 130, 30, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "13" :
Item (x) := "Milk"
Price (x) := 1.69
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID15, 140, 0, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "14" :
Item (x) := "Hot Chocolate"
Price (x) := 1.69
Price_New (x) := Price (x)


winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID16, 110, -60, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "15" :
Item (x) := "Coffee"
Price (x) := 1.29
Price_New (x) := Price (x)

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
Pic.DrawSpecial (picID17, 70, -60, picCopy, picFadeIn, 3000)
delay (1500)
Window.Close (winID3)
exit
label "16" :
cls
leave := true
x := x - 1
exit
label :

winID3 := Window.Open ("position:bottom;center,graphics:641;260")
put ""
put ""
put ""
put ""
put ""
put " Please enter a valid order number."
delay (1000)
exit
end case
end loop
exit when Selection = "16"

loop
put "How many of order ", Selection, " would you like to order?"
put "Quantity: " ..
get Quantity (x)
exit
end loop
end loop
cls

Item_Total (x) := 0
Sub_Total := 0

Item_Total (x) := Price (x) * Quantity (x)
Sub_Total := Sub_Total + Item_Total (x)

put "Item"
put "Price"
put "Quantity"
put "Total"

hst := Sub_Total * 0.13
Gratuity := (Sub_Total) * 0.15
Total := Sub_Total + hst + Gratuity


for z : 1 .. x
Price_String (y) := realstr (Price (y), 10)
Quantity_String (y) := realstr (Quantity (y), 10)
ItemTotal_String (y) := realstr (Item_Total (y), 10)
put Item (y)
put Price_String (y)
put Quantity_String (y)
put ItemTotal_String (y)
end for

put "Subtotal", Sub_Total
put "Hst", hst
if Sub_Total >= 10 then
put "Gratuity", Gratuity
end if
put "Total", Total
put "Enjoy your meal!"
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Mon Apr 30, 2012 3:22 pm   Post subject: RE:Turing Menu

Where does it crash, and what message does it give you when it crashes?
IsStickel




PostPosted: Mon Apr 30, 2012 5:18 pm   Post subject: Re: RE:Turing Menu

Dreadnought @ Mon Apr 30, 2012 3:22 pm wrote:
Where does it crash, and what message does it give you when it crashes?


It crashes right here:

Price_String (y) := realstr (Price (y), 10)
Quantity_String (y) := realstr (Quantity (y), 10)
ItemTotal_String (y) := realstr (Item_Total (y), 10)

and it says variable has no value
Tony




PostPosted: Mon Apr 30, 2012 5:21 pm   Post subject: RE:Turing Menu

when that line gets executed, what is the value of variable y ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
IsStickel




PostPosted: Mon Apr 30, 2012 5:30 pm   Post subject: Re: RE:Turing Menu

Tony @ Mon Apr 30, 2012 5:21 pm wrote:
when that line gets executed, what is the value of variable y ?


I'm not exactly sure. I'm a beginner with turing and have had a few people help me out on this, but no one seems to know the error or how to make it run properly.
Tony




PostPosted: Mon Apr 30, 2012 5:55 pm   Post subject: RE:Turing Menu

hint: you can simply ask for the value to be displayed
code:

put "value of y is: ", y
Price_String (y) := realstr (Price (y), 10)
Quantity_String (y) := realstr (Quantity (y), 10)
ItemTotal_String (y) := realstr (Item_Total (y), 10)


the error message should be pretty clear -- if there is no value, the computer wouldn't know what to display or what element of the Price array to use.

What do you expect the value to be? The fix would be the changes to the code such that you can determine that the value you want is the one that gets used.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
IsStickel




PostPosted: Mon Apr 30, 2012 6:14 pm   Post subject: Re: RE:Turing Menu

Tony @ Mon Apr 30, 2012 5:55 pm wrote:
hint: you can simply ask for the value to be displayed
code:

put "value of y is: ", y
Price_String (y) := realstr (Price (y), 10)
Quantity_String (y) := realstr (Quantity (y), 10)
ItemTotal_String (y) := realstr (Item_Total (y), 10)


the error message should be pretty clear -- if there is no value, the computer wouldn't know what to display or what element of the Price array to use.

What do you expect the value to be? The fix would be the changes to the code such that you can determine that the value you want is the one that gets used.


I'll try, thanks..
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  [ 7 Posts ]
Jump to:   


Style:  
Search: