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

Username:   Password: 
 RegisterRegister   
 How to close a window based on condition statement
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Da_Big_Ticket




PostPosted: Wed May 25, 2005 3:38 pm   Post subject: How to close a window based on condition statement

If doing a program that requires user input. Its for CSIS - it asks questions like whats your age, your weight, your iq, and whether your fluent in french and irish. With these questions are conditions. You only qualify if your age is under 30, your weight is over 180, your iq is over 150, and your fluent in french and irish. I need the program to automatically stop and have the window close AS SOON AS someone inputs something wrong (eg age over 30, when you only qualify if it is less. This is my code so far:

code:
var iq, weight, age : real
var french, irish, openpic, font1, font2, window, winID : int

openpic := Pic.FileNew ("e:/csis.jpg")
font1 := Font.New ("Microsoft Sans Sertif:16")
font2 := Font.New ("Bradley Hand Itc:12")
winID:= Window.Open ("position: 0;800, graphics:650;400")
Pic.Draw (openpic, 0, 0, picCopy)
delay (4000)
cls

Font.Draw ("Csis, my hero questionaire. Please fill out.", 100, 370, font1, blue)
Font.Draw ("Enter your age, please.", 10, 350, font2, red)
locate (5, 3)
get age
if age < 30 then
    Font.Draw ("Enter your weight, please.", 10, 305, font2, red)
    locate (7, 3)
    else
    put "Sorry, you didnt make the cut" 
    Window.Close (winID)
    get weight
    if weight >= 180 then
        Font.Draw ("Enter your french fluency (1-10), please.", 10, 260, font2, red)
        locate (10, 3)
        get french
        if french >= 9 then
            Font.Draw ("Enter your irish fluency (1-10), please.", 10, 210, font2, red)
            locate (13, 3)
            get irish
            if irish >= 9 then
                Font.Draw ("Enter your iq, please.", 10, 180, font2, red)
                locate (15, 3)
                get iq
                if iq > 150 then
                    Font.Draw ("Calculating your results...", 10, 130, font1, blue)
                    if iq > 150 and weight > 180 and french > 9 and irish > 9 then
                        delay (1000)
                        Font.Draw ("Great questionaire, yee haw you made the cut.", 10, 100, font2, red)
                    end if
                end if
            end if
        end if
    end if


end if


Now my idea was a window.close procedure after each condition line. However, for a window.close statement to work, it needs an window id with it. When i make this the window will be made and closed, but will leave an original window behind. I need someone to explain how to fix this problem with the necessary code
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Wed May 25, 2005 3:45 pm   Post subject: (No subject)

code:
var iq, weight, age : real
var french, irish, openpic, font1, font2, window, winID : int

openpic := Pic.FileNew ("e:/csis.jpg")
font1 := Font.New ("Microsoft Sans Sertif:16")
font2 := Font.New ("Bradley Hand Itc:12")
winID := Window.Open ("position: 0;800, graphics:650;400")
Pic.Draw (openpic, 0, 0, picCopy)
delay (4000)
cls


Font.Draw ("Csis, my hero questionaire. Please fill out.", 100, 370, font1, blue)
Font.Draw ("Enter your age, please.", 10, 350, font2, red)
locate (5, 3)
get age
if age < 30 then
    Window.Close (winID)
else
    put "Sorry, you didnt make the cut"
    Window.Close (winID)
    get weight
    if weight >= 180 then
        Font.Draw ("Enter your french fluency (1-10), please.", 10, 260, font2, red)
        locate (10, 3)
        get french
        if french >= 9 then
            Font.Draw ("Enter your irish fluency (1-10), please.", 10, 210, font2, red)
            locate (13, 3)
            get irish
            if irish >= 9 then
                Font.Draw ("Enter your iq, please.", 10, 180, font2, red)
                locate (15, 3)
                get iq
                if iq > 150 then
                    Font.Draw ("Calculating your results...", 10, 130, font1, blue)
                    if iq > 150 and weight > 180 and french > 9 and irish > 9 then
                        delay (1000)
                        Font.Draw ("Great questionaire, yee haw you made the cut.", 10, 100, font2, red)
                    end if
                end if
            end if
        end if
    end if


end if

Is this what you mean, tr entering the age less than 30. it works for me Confused
Da_Big_Ticket




PostPosted: Wed May 25, 2005 4:25 pm   Post subject: (No subject)

Well I got it to work this way. (look at bottom) The wierd thing is that turing is very picky, i had to make it "if age>=30 then Window.close," instead of "else if window.close". This way it dosent close then leave another run window behind it (why i dont know) If anyone has an explanation to why
code:

if age >= 30 then
    delay (400)
    Window.Close (window)


dosent leave a second window but

code:
if age < 30 then
    Font.Draw ("Enter your weight, please.", 10, 305, font2, red)
else
window.close (window)


does, id like to know

code:

var iq, weight, age : real
var french, irish, openpic, font1, font2, window : int

openpic := Pic.FileNew ("e:/csis.jpg")
font1 := Font.New ("Microsoft Sans Sertif:16")
font2 := Font.New ("Bradley Hand Itc:12")
window := Window.Open ("position: 0;800, graphics:650;400")
Pic.Draw (openpic, 0, 0, picCopy)
delay (4000)
cls

Font.Draw ("Csis, my hero questionaire. Please fill out.", 100, 370, font1, blue)
Font.Draw ("Enter your age, please.", 10, 350, font2, red)
locate (5, 3)
get age
if age >= 30 then
    delay (400)
    Window.Close (window)
else
    Font.Draw ("Enter your weight, please.", 10, 305, font2, red)
    locate (7, 3)
    get weight
    if weight <= 180 then
        delay (400)
        Window.Close (window)
    else
        Font.Draw ("Enter your french fluency (1-10), please.", 10, 260, font2, red)
        locate (10, 3)
        get french
        if french <= 9 then
            delay (400)
            Window.Close (window)
        else
            Font.Draw ("Enter your irish fluency (1-10), please.", 10, 210, font2, red)
            locate (13, 3)
            get irish
            if irish <= 9 then
                delay (400)
                Window.Close (window)
                Font.Draw ("Enter your iq, please.", 10, 180, font2, red)
                locate (15, 3)
                get iq
                if iq < 150 then
                    delay (400)
                    Window.Close (window)
                else
                    Font.Draw ("Calculating your results...", 10, 130, font1, blue)
                    if iq > 150 and weight > 180 and french > 9 and irish > 9 then
                        delay (1000)
                        Font.Draw ("Great questionaire, yee haw you made the cut.", 10, 100, font2, red)
                    end if
                end if
            end if
        end if
    end if
end if
StarGateSG-1




PostPosted: Wed May 25, 2005 4:46 pm   Post subject: (No subject)

That is simple, the command is elsif, I think that is what you mean.
Bacchus




PostPosted: Wed May 25, 2005 7:07 pm   Post subject: (No subject)

when you say if their fluent in Irish, do you mean if their fluent in Gaelic?
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  [ 5 Posts ]
Jump to:   


Style:  
Search: