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

Username:   Password: 
 RegisterRegister   
 Problem with exiting loops
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lightwepon




PostPosted: Mon Apr 08, 2013 6:49 am   Post subject: Problem with exiting loops

What is it you are trying to achieve?
I am trying to exit more than 1 loop when i get to "Would you like to order again". Are there also more ways to do what i want to achieve in my code by using less loops?


What is the problem you are having?
When it gets to , "Would you like to order again?", it exits the first loop. I would like it to exit so that it goes to the end where it calculates the receipt.



Describe what you have tried to solve this problem
Putting exits


Turing:


%Restaurant Menu
var day, final_total, subtotal : real
var name, select, menu, today, quiz, reply : string
var y, font1, font2, numorders, ordernumber, luckycustomer : int
var q, x : int := 0
var item : array 1 .. 3 of string
var quantity : array 1 .. 3 of int
var price : array 1 .. 3 of real
var ans : string (1)
var winID : int
var tax : real := 0
var category, selection, anykey : string (1)
var finished, finished2, inputOK : boolean := false
winID := Window.Open ("position:top;center,graphics:700;700")
y := 3
q := 0
font1 := Font.New ("comicsans:18")
font2 := Font.New ("impact:15")
numorders := 0
date (today)
Draw.FillBox (0, 0, maxx, maxy, 15)
colourback (15)


procedure menuoptions
    Font.Draw ("Menu", 295, 620, font2, 52)
    locate (9, 1)
    put "1. Burgers" : 16 ..
    put "2. Fries" : 16 ..
    put "3. Drink" : 16 ..
    put "4. Sides" : 16 ..
    put "5. Custom Burger"
    put " "
end menuoptions
procedure invalidresponse
    put "Invalid selection, please retry"
    put "Press any key to continue"
    getch (anykey)
    cls
end invalidresponse
process BackgroundMusic
    loop
        exit when finished
        Music.PlayFile ("The Super Mario Song.mp3")
    end loop
end BackgroundMusic
fork BackgroundMusic
procedure coupon
    locate (15, 1)
    put "The coupon code is : 1337panda"
end coupon
procedure Startpage
    put today
    put "Welcome to Mario's Burger Joint!"
    setscreen ("graphics:700;700")
    put "Press any key to continue : "
    loop
        exit when hasch
    end loop
    %Coupon
    randint (luckycustomer, 0, 1)
    if luckycustomer = 1 then
        put "Congratulations! You are the 100th Customer today, enjoy a free coupon!"
        var button1 : int := GUI.CreateButton (300, 300, 150, "Click here for a coupon!", coupon)
        var button2 : int := GUI.CreateButton (300, 500, 0, "Continue", GUI.Quit)
        loop
            exit when GUI.ProcessEvent
        end loop
    else
    end if
    cls
    finished := true
    Music.PlayFileStop
end Startpage
%Yoshi's Remix of Mario theme song (Background Music)
process BackgroundMusic2
    loop
        exit when finished2
        Music.PlayFile ("preview.mp3")
    end loop
end BackgroundMusic2
fork BackgroundMusic2
%Page Setting and lettering size
Draw.FillBox (0, 0, maxx, maxy, 42)
colourback (42)
color (31)
for i : 1 .. 3
    quantity (i) := 0
    item (i) := " "
    price (i) := 0
end for
%Startpage
locate (9, 1)
Input.Flush
put "How may I address you?"
get name : *
cls
put "Hello, ", name, "!"
put "The menu is below, please take your time to order."
loop
    loop
        menuoptions
        put "Select a category by inputting the number of the category."
        getch (category)
        if category = "1" then
            put "1.Cheese Burger..$5.00"
            put "X", quantity (1)
            put "2.Bacon Burger...$5.25"
            put "3.Veggie Burger..$5.00"
            locate (19, 1)
            put "Please pick your an item by inputting the number (To return to menu press 0):"
            getch (selection)
            if "0" < selection and selection < "4" then
                %Quantity
                locate (19, 1)
                put "Please enter how many you would like:"
                get q
                Input.Flush
                if q < 0 or q > 100 then
                    invalidresponse
                end if
                %Menu Options
                case selection of
                    label "1" :
                        item (1) := "Cheese Burger"
                        price (1) := 5.00
                        quantity (1) := quantity (1) + q
                        inputOK := true
                    label "2" :
                        item (2) := "Bacon Burger"
                        price (2) := 5.25
                        quantity (2) := quantity (2) + q
                        inputOK := true
                    label "3" :
                        item (3) := "Veggie Burger"
                        price (3) := 5.00
                        quantity (3) := quantity (3) + q
                        inputOK := true
                end case
                q := 0
            elsif selection = "0" then
                put "Would you like to add another selection to your order? If yes type anything, if no type (n)"
                getch (ans)
                exit when ans = "n" or ans = "N"
                cls
            else
                invalidresponse
            end if
            exit
        else
            exit
        end if
        exit
    end loop
    for i : 1 .. 3
        if item (i) = " " then
            put "You haven't ordered anything! You will be redirected momentarily."
            cls
        end if
        exit
    end for

end loop
%Receipt
cls
put "Customer Name : ", name
put "Date:", today
%if luckycustomer = 1 then
ordernumber := 100
%else
randint (ordernumber, 1, 100)
%end if
put "Order Number : ", ordernumber
put "Final Total"
put "Item" : 20 ..
put "Price of Item" : 20 ..
put "Quantity" : 20
for i : 1 .. 3
    if quantity (i) not= 0 then
        put item (i), ":", price (i) : 20, quantity (i) : 20
        put "Subtotal : " ..
        subtotal := price (i) * quantity (i)
        put subtotal
    end if
end for
put "Final Total (Including tax):" ..
for i : 1 .. 3
    tax := tax + price (i) * quantity (i) * 0.13
end for
put "Tax : " ..
put tax
final_total := subtotal + tax
put final_total : 0 : 2
finished2 := true
Music.PlayFileStop






Please specify what version of Turing you are using
4.0.5
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Apr 08, 2013 7:45 am   Post subject: RE:Problem with exiting loops

It looks to me like you don't need that outer loop at all.
lightwepon




PostPosted: Mon Apr 08, 2013 9:22 am   Post subject: Re: Problem with exiting loops

The outer loop is to loop the user back if they ordered nothing i think Razz
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  [ 3 Posts ]
Jump to:   


Style:  
Search: