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

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




PostPosted: Sun Apr 22, 2012 12:48 am   Post subject: Turing Array Problem Help!

Hi. I have to make a program that simulates a restaurant for school and it has to print out a bill and i am having trouble getting the selected items to be displayed after the user exits the loop. When i try to display items, it only puts the last selected item and if i try using a for loop to display the items i don't know what range to use. If someone could help me out it would be greatly appreciated!

code:


% this program was created by Kazim Haider
% this program was created on April 16th
% this program simulates a restaurant menu

% declare variables
var item : array 1 .. 20 of string
var amount : array 1 .. 20 of string
var Amount : array 1 .. 20 of int
var total : array 1 .. 20 of real
var finalTot : real
var price : array 1 .. 20 of real
var invoice : int
var gratuity : real
var hst : real
var reply : string
var Reply : 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 picID19 : int
var picID20 : int
var picID21 : int
var picID22 : int
var picID23 : int
var picID24 : int
var picID25 : int
var picID26 : int
var picID27 : int
var picID28 : int
var picID29 : int
var picID30 : int
var picID31 : int
var picID32 : int
var done : boolean := false
var winID : int
var x : int := 0
var response : string (1)

% storing the pictures in the variables
picID := Pic.FileNew ("Intro.jpg")
picID2 := Pic.FileNew ("RestaurantInterior.jpg")
picID3 := Pic.FileNew ("ShrimpFriedrice.jpg")
picID4 := Pic.FileNew ("SteakDinner.jpg")
picID5 := Pic.FileNew ("ChickenDish.jpg")
picID6 := Pic.FileNew ("fettucini.jpg")
picID7 := Pic.FileNew ("CaesarSalad.jpg")
picID8 := Pic.FileNew ("EggsBenedict.jpg")
picID9 := Pic.FileNew ("SteamedRice.jpg")
picID10 := Pic.FileNew ("Pasta.jpg")
picID11 := Pic.FileNew ("FiletMignon.jpg")
picID12 := Pic.FileNew ("Lasagna.jpg")
picID13 := Pic.FileNew ("Pizza.jpg")
picID14 := Pic.FileNew ("Omelette.jpg")
picID15 := Pic.FileNew ("Chili.jpg")
picID16 := Pic.FileNew ("Poutine.jpg")
picID17 := Pic.FileNew ("Lobster.jpg")
picID18 := Pic.FileNew ("RoastBeef.jpg")
picID19 := Pic.FileNew ("ShishKebab.jpg")
picID20 := Pic.FileNew ("MacNCheese.jpg")
picID21 := Pic.FileNew ("ColeSlaw.jpg")
picID22 := Pic.FileNew ("PotatoSalad.jpg")
picID23 := Pic.FileNew ("Soda.jpg")
picID24 := Pic.FileNew ("Coffee.jpg")
picID25 := Pic.FileNew ("Milkshake.jpg")
picID26 := Pic.FileNew ("IcedCoffee.jpg")
picID27 := Pic.FileNew ("Water.jpg")
picID28 := Pic.FileNew ("BottledWater.jpg")
picID29 := Pic.FileNew ("HotChocolate.jpg")
picID30 := Pic.FileNew ("Tea.jpg")
picID31 := Pic.FileNew ("IcedTea.jpg")
picID32 := Pic.FileNew ("BubbleTea.jpg")

% customizing the window size
winID := Window.Open ("graphics:800;720")

% process for music
process music
    loop
        % song that is going to be played
        Music.PlayFile ("Music.mp3")
        % exit statement to end the song when program finishes
        exit when done
    end loop
end music

% playing the music
fork music

% setting background colour
colorback (blue)
cls

% intro screen
Pic.DrawSpecial (picID, 50, 75, picCopy, picFadeIn, 2000)
delay (4500)
cls

% introduction
put "Welcome to Cerulean!"
Pic.DrawSpecial (picID2, 175, 200, picCopy, picFadeIn, 2000)
delay (4000)
cls
put "This will be your best dining experience ever!"
delay (1000)
put "You will see our menu and will be asked to choose what you would like to order."
delay (4000)
put "If your order is over $10, then a fee of 15% will be charged."
delay (3000)
put "We hope you enjoy your experience!"
delay (4500)
cls

% generating random invoice number
randint (invoice, 1, 500)

loop
    x := x + 1
    loop
        % dummy proofing
        loop
            %  displaying the menu of items
            put "Food Items" : 20, "" : 10, "Price ($)" : 19, "Drinks" : 20, "Price ($)" : 9
            put repeat ("-", 80)
            put "1. Shrimp Fried Rice" : 20, 8.99 : 14, "" : 14, "21. Soda" : 20, 1.99 : 5
            put "2. Steak Plate" : 20, 11.99 : 14, "" : 14, "22. Coffee" : 20, 1.39 : 5
            put "3. Chicken Dish" : 20, 9.99 : 14, "" : 14, "23. Mango Milkshake" : 20, 2.59 : 5
            put "4. Fettucini Alfredo" : 20, 8.99 : 14, "" : 14, "24. Iced Coffee" : 20, 1.79 : 5
            put "5. Caesar Salad" : 20, 5.99 : 14, "" : 14, "25. Water" : 20, "Free!" : 5
            put "6. Eggs Benedict" : 20, 5.99 : 14, "" : 14, "26. Bottled Water" : 20, 1.99 : 5
            put "7. Steamed Rice" : 20, 4.99 : 14, "" : 14, "27. Hot Chocolate" : 20, 1.99 : 5
            put "8. Pasta w/ Sauce" : 20, 7.99 : 14, "" : 14, "28. Tea" : 20, 1.99 : 5
            put "9. Filet Mignon" : 20, 9.99 : 14, "" : 14, "29. Iced Tea" : 20, 1.39 : 5
            put "10. Lasagna" : 20, 8.99 : 14, "" : 14, "30. Bubble Tea" : 20, 1.99 : 5
            put "11. Meat Pizza" : 20, 9.99 : 14
            put "12. Cheese Omelette" : 20, 6.99 : 14
            put "13. Chili" : 20, 6.99 : 14
            put "14. Poutine" : 20, 6.99 : 14
            put "15. Lobster Tail" : 20, 9.99 : 14
            put "16. Roast Beef" : 20, 9.99 : 14
            put "17. Shish Kebab" : 20, 8.99 : 14
            put "18. Mac 'n Cheese" : 20, 4.99 : 14
            put "19.Cole Slaw" : 20, 3.99 : 14
            put "20. Potato Salad" : 20, 3.99 : 14
            put ""
            put "Please enter the number beside your chosen dish/drink here ==>" ..

            % getting user input
            get reply
            exit when strintok (reply)
            put "Please enter an appropriate value!"
            delay (1500)
            cls
        end loop

        % converting string to an integer
        Reply := strint (reply)

        if Reply < 1 or Reply > 30 then
            put "Please enter an appropriate value!"
            delay (1500)
            cls
        elsif Reply >= 1 or Reply <= 30 then
            exit
        end if
    end loop

    delay (1000)
    cls
   
    case Reply of
        label 1 :
            Pic.DrawSpecial (picID3, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Shrimp Fried Rice"
            price (x) := 8.99
        label 2 :
            Pic.DrawSpecial (picID4, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Steak Plate"
            price (x) := 11.99
        label 3 :
            Pic.DrawSpecial (picID5, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Chicken Dish"
            price (x) := 9.99
        label 4 :
            Pic.DrawSpecial (picID6, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Fettucini Alfredo"
            price (x) := 8.99
        label 5 :
            Pic.DrawSpecial (picID7, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Caesar Salad"
            price (x) := 5.99
        label 6 :
            Pic.DrawSpecial (picID8, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Eggs Benedict"
            price (x) := 5.99
        label 7 :
            Pic.DrawSpecial (picID9, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Steamed Rice"
            price (x) := 4.99
        label 8 :
            Pic.DrawSpecial (picID10, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Pasta w/ Sauce"
            price (x) := 7.99
        label 9 :
            Pic.DrawSpecial (picID11, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Filet Mignon"
            price (x) := 9.99
        label 10 :
            Pic.DrawSpecial (picID12, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Lasagna"
            price (x) := 8.99
        label 11 :
            Pic.DrawSpecial (picID13, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Meat Pizza"
            price (x) := 9.99
        label 12 :
            Pic.DrawSpecial (picID14, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Cheese Omelette"
            price (x) := 6.99
        label 13 :
            Pic.DrawSpecial (picID15, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Chili"
            price (x) := 6.99
        label 14 :
            Pic.DrawSpecial (picID16, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Poutine"
            price (x) := 6.99
        label 15 :
            Pic.DrawSpecial (picID17, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Lobster Tail"
            price (x) := 9.99
        label 16 :
            Pic.DrawSpecial (picID18, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Roast Beef"
            price (x) := 9.99
        label 17 :
            Pic.DrawSpecial (picID19, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Shish Kebab"
            price (x) := 8.99
        label 18 :
            Pic.DrawSpecial (picID20, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Mac 'n Cheese"
            price (x) := 4.99
        label 19 :
            Pic.DrawSpecial (picID21, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Cole Slaw"
            price (x) := 3.99
        label 20 :
            Pic.DrawSpecial (picID22, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Potato Salad"
            price (x) := 3.99
        label 21 :
            Pic.DrawSpecial (picID23, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Soda"
            price (x) := 1.99
        label 22 :
            Pic.DrawSpecial (picID24, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Coffee"
            price (x) := 1.39
        label 23 :
            Pic.DrawSpecial (picID25, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Mango Milkshake"
            price (x) := 2.59
        label 24 :
            Pic.DrawSpecial (picID26, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Iced Coffee"
            price (x) := 1.79
        label 25 :
            Pic.DrawSpecial (picID27, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Water"
            price (x) := 0.00
        label 26 :
            Pic.DrawSpecial (picID28, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Bottled Water"
            price (x) := 1.99
        label 27 :
            Pic.DrawSpecial (picID29, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Hot Chocolate"
            price (x) := 1.99
        label 28 :
            Pic.DrawSpecial (picID30, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Tea"
            price (x) := 1.99
        label 29 :
            Pic.DrawSpecial (picID31, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Iced Tea"
            price (x) := 1.39
        label 30 :
            Pic.DrawSpecial (picID32, 175, 200, picCopy, picFadeIn, 2000)
            item (x) := "Bubble Tea"
            price (x) := 1.99
        label :
            put "Please enter an appropriate value!"
            delay (1500)
            cls
    end case

    loop
        % dummy proofing
        loop
            put "How many of that would you like?" ..
            get amount (x)
            exit when strintok (amount (x))
            put "Please enter an appropriate value!"
            delay (1500)
            cls
        end loop

        % converting string to an integer
        Amount (x) := strint (amount (x))

        % making sure negative numbers cannot be entered
        if Amount (x) < 0 then
            put "Please enter an appropriate value!"
            delay (1500)
            cls
        else
            exit
        end if
    end loop

    put "Would you like to get your bill? Press 'x' to get your bill or anything else to continue" ..
    getch (response)
    cls
    % exit statement
    exit when response = "X" or response = "x"
end loop


Thanks!
Sponsor
Sponsor
Sponsor
sponsor
Amarylis




PostPosted: Sun Apr 22, 2012 7:22 pm   Post subject: RE:Turing Array Problem Help!

I'd just like to point out that making two variable names be almost identical is generally seen as "poor form" (amount and Amount arrays)


Also, could you please attach the images that you need? I can't quite understand what the problem was, and I can't see it for myself without all the required files (And I'm guessing others may also have a problem)
Newspaper




PostPosted: Sun Apr 22, 2012 7:57 pm   Post subject: Re: RE:Turing Array Problem Help!

Amarylis @ Sun Apr 22, 2012 7:22 pm wrote:
I'd just like to point out that making two variable names be almost identical is generally seen as "poor form" (amount and Amount arrays)


Also, could you please attach the images that you need? I can't quite understand what the problem was, and I can't see it for myself without all the required files (And I'm guessing others may also have a problem)


Sure i'll do that and I wanted amount to stay as amount when I converted it using strint I could change it but it just makes it easier for me. The problem I am facing is to get it to display the selected items in a column after the initial selection process is over.



KazimRestaurant.rar
 Description:
All of the images + music file + code.

Download
 Filename:  KazimRestaurant.rar
 Filesize:  6.4 MB
 Downloaded:  115 Time(s)

Amarylis




PostPosted: Sun Apr 22, 2012 8:18 pm   Post subject: RE:Turing Array Problem Help!

Personally speaking, I'd just use a dummy check string variable, and just check that variable, as opposed to having a string and integer copy of any value


The program is fairly neat, and it's good that you do have a dummy check

Okay, so, I just have a question about your code- Why the "total" array?

The way I can see it is to just have a "total" real variable, so that way you're keeping track of the total that they've got for all the orders.

And as for displaying what they ordered, one way that I can see would be to use a for loop of 1 .. x, and just use that as the array subscripts

Last note: I find it unnecessary to have 2 out-of-bounds checks (I'm talking both the Reply ones, where you first have an if statement and then you have a label in your case for it as well)

Edit (again): Okay, I know I said that the last one was the last note, but I guess I lied. You might want to consider using Pic.Free as well to free some of those picture variables when they're not needed, and only having 1 picture variable for every picture you need on screen at once (e.g. if you need to have 3 pictures at once on screen, have 3 picture variables, 2 pictures on screen at once, 2 variables, etc)

Also, the blue background kinda hurts my eyes when trying to read it, though it may just be me

The program is good though Smile
Newspaper




PostPosted: Mon Apr 23, 2012 2:56 pm   Post subject: Re: RE:Turing Array Problem Help!

Amarylis @ Sun Apr 22, 2012 8:18 pm wrote:
Personally speaking, I'd just use a dummy check string variable, and just check that variable, as opposed to having a string and integer copy of any value


The program is fairly neat, and it's good that you do have a dummy check

Okay, so, I just have a question about your code- Why the "total" array?

The way I can see it is to just have a "total" real variable, so that way you're keeping track of the total that they've got for all the orders.

And as for displaying what they ordered, one way that I can see would be to use a for loop of 1 .. x, and just use that as the array subscripts

Last note: I find it unnecessary to have 2 out-of-bounds checks (I'm talking both the Reply ones, where you first have an if statement and then you have a label in your case for it as well)

Edit (again): Okay, I know I said that the last one was the last note, but I guess I lied. You might want to consider using Pic.Free as well to free some of those picture variables when they're not needed, and only having 1 picture variable for every picture you need on screen at once (e.g. if you need to have 3 pictures at once on screen, have 3 picture variables, 2 pictures on screen at once, 2 variables, etc)

Also, the blue background kinda hurts my eyes when trying to read it, though it may just be me

The program is good though Smile


Thank you. I have made the suggested changes. The issue of displaying the items still persists how ever. "x" has the value of how ever many times it ran through the loop, lets say 2 times. When I display items in a for loop, it puts the last selected items 2 times in this case. If it ran through the loop 3 times it would put the item 3 times. Sorry if this is a bit troubling haha. I am almost finished the program, just have to figure this problem out quickly as it is due on Wednesday!
Amarylis




PostPosted: Mon Apr 23, 2012 7:05 pm   Post subject: RE:Turing Array Problem Help!

try this:

[syntax="Turing]
for i : 1 .. x
put item (i), ": " price (i)
end for

put "Total was: $", total
[/syntax]
evildaddy911




PostPosted: Mon Apr 23, 2012 8:15 pm   Post subject: RE:Turing Array Problem Help!

one thing i suggest, just to make it look nicer, is that you put the picture variables in an array, or just declare them all on the same line i may also suggest looking into records for the amount, Amount, price, item and total arrays. other that that, the program lokks great!
Newspaper




PostPosted: Mon Apr 23, 2012 10:30 pm   Post subject: Re: RE:Turing Array Problem Help!

evildaddy911 @ Mon Apr 23, 2012 8:15 pm wrote:
one thing i suggest, just to make it look nicer, is that you put the picture variables in an array, or just declare them all on the same line i may also suggest looking into records for the amount, Amount, price, item and total arrays. other that that, the program lokks great!


Hey thanks for the suggestion. I have already implemented the suggested changes Smile.
Sponsor
Sponsor
Sponsor
sponsor
Newspaper




PostPosted: Mon Apr 23, 2012 10:37 pm   Post subject: Re: RE:Turing Array Problem Help!

Amarylis @ Mon Apr 23, 2012 7:05 pm wrote:
try this:

[syntax="Turing]
for i : 1 .. x
put item (i), ": " price (i)
end for

put "Total was: $", total
[/syntax]


Hey, that did the trick! Thanks a lot! Smile
Amarylis




PostPosted: Mon Apr 23, 2012 10:50 pm   Post subject: RE:Turing Array Problem Help!

No problem, I think you were just getting caught up in using the same array subscript
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  [ 10 Posts ]
Jump to:   


Style:  
Search: