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

Username:   Password: 
 RegisterRegister   
 Question in a question
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DVL_IAC




PostPosted: Sat Feb 12, 2005 11:38 pm   Post subject: Question in a question

How would i ask a 2 answer question (like y or n) then if they said y it brings another y or n question.... its hard to explain what i mean...

ex:
code:

var choice : string
put "do you want to listen to music? (y or n)"
get choice
if choice = "y" then
put "ok"
delay (1000)
var i : int := 0
  Music.PlayFileLoop ("musicfile1")
delay (10000)
put "do you want to change songs (y or n)?"
get choice
if choice = "y" then
put "changing..."
delay (1000)
var j : int := 0
        Music.PlayFileLoop ("musicfile2")
        else
        put "kk"
then here put if the answer was n to the first question what the program should do...


how would i do that? Confused I just started the grade 10 comp info sci course and were only like a week into it so i'm a complete turing n00b Posted Image, might have been reduced in size. Click Image to view fullscreen.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Feb 12, 2005 11:48 pm   Post subject: (No subject)

you could build out if - elsif - else structure.
1337_brad




PostPosted: Sun Feb 13, 2005 12:21 am   Post subject: You could also use processes

you could use a process so that the music starts playing, and it starts to ask the user if he wants to change songs...

[/code]
DVL_IAC




PostPosted: Sun Feb 13, 2005 10:32 pm   Post subject: (No subject)

tony wrote:
you could build out if - elsif - else structure.


i clicked the link and read and im confused. Posted Image, might have been reduced in size. Click Image to view fullscreen.

i put
code:
var choice : string
put "do you want to listen to music? (y or n)"
get choice
if choice = "y" then
put "ok"
delay (1000)
var i : int := 0
  Music.PlayFileLoop ("PhobosAnomaly.mid")
delay (10000)
put "do you want to change songs (y or n)?"
get choice
if choice = "y" then
put "changing..."
delay (1000)
var j : int := 0
        Music.PlayFileLoop ("VictorEndofEpisode.mid")
        elsif choice = "n" then
        put "kk"
        else
        put "Fine then!" ..
        delay (1000)
        put "Be that way!"
        delay (10000)
end if
end if


and when the person puts n as the answer to the first question the program just stops and doesnt say "Fine Then! Be that way!" Posted Image, might have been reduced in size. Click Image to view fullscreen.

i'm guessing im not understanding the if - elsif - else thing right Posted Image, might have been reduced in size. Click Image to view fullscreen.
cycro1234




PostPosted: Mon Feb 14, 2005 8:26 am   Post subject: (No subject)

You could also try declaring each choice as a variable at the beginning of ur program. So like:

var choice1, choice2, choice3 : string

Then using each on individually in ur program. This way the program remembers what the value of choice1 is, and so on.
Tony




PostPosted: Mon Feb 14, 2005 10:31 am   Post subject: (No subject)

DVL_IAC wrote:
i'm guessing im not understanding the if - elsif - else thing right

it understands it alright - computers don't make mistakes. You just wrote it down wrong Laughing

Use F2 to indent your code and take a look at your structure closely. Try to follow it through in your head.
DVL_IAC




PostPosted: Mon Feb 14, 2005 5:30 pm   Post subject: (No subject)

cycro1234 wrote:
You could also try declaring each choice as a variable at the beginning of ur program. So like:

var choice1, choice2, choice3 : string

Then using each on individually in ur program. This way the program remembers what the value of choice1 is, and so on.


hmm like this
code:

var choice1, choice2 : string
put "do you want to listen to music? (y or n)"
get choice1
if choice1 = "y" then
    put "ok"
    delay (1000)
    var i : int := 0
    Music.PlayFileLoop ("PhobosAnomaly.mid")
    delay (10000)
    put "do you want to change songs (y or n)?"
    get choice2
    if choice2 = "y" then
        put "changing..."
        delay (1000)
        var j : int := 0
        Music.PlayFileLoop ("VictorEndofEpisode.mid")
    elsif choice2 = "n" then
        put "kk"
    elsif choice1 = "n" then
        put "Fine then!" ..
        delay (1000)
        put "Be that way!"
        delay (10000)
    end if
end if

?
or like this

code:

var choice1, choice2 : string
put "do you want to listen to music? (y or n)"
get choice1
if choice1 = "y" then
    put "ok"
    delay (1000)
    var i : int := 0
    Music.PlayFileLoop ("PhobosAnomaly.mid")
    delay (10000)
    put "do you want to change songs (y or n)?"
    get choice2
    if choice2 = "y" then
        put "changing..."
        delay (1000)
        var j : int := 0
        Music.PlayFileLoop ("VictorEndofEpisode.mid")
        if choice2 = "n" then
            put "kk"
            if choice1 = "n" then
                put "Fine then!" ..
                delay (1000)
                put "Be that way!"
                delay (10000)
            end if
        end if
    end if
end if

?

hmm both ways it still finishes the program when you put n as the answer to the first question.

Tony wrote:

Use F2 to indent your code and take a look at your structure closely. Try to follow it through in your head.


I did and it seams fine to me... Confused
Bacchus




PostPosted: Mon Feb 14, 2005 5:39 pm   Post subject: (No subject)

put one end if right after the if chioce2="n" then kk thing and remove one at the end right now ur checking to see if chioce1 in "n" in the check to see if chioce1="y"
Sponsor
Sponsor
Sponsor
sponsor
DVL_IAC




PostPosted: Tue Feb 15, 2005 6:20 pm   Post subject: (No subject)

ok i got it to continue when you push n on the first question.. Smile

code:

var choice1 : string
var choice2 : string
put "do you want to listen to music? (y or n)"
get choice1
if choice1 = "y" then
    put "ok"
    delay (1000)
    var i : int := 0
    Music.PlayFileLoop ("shortfile1.wav")
end if
delay (7000)
put "do you want to change songs (y or n)?"
get choice2
if choice2 = "y" then
    put "changing..."
    delay (1000)
    var j : int := 0
    Music.PlayFileLoop ("shortfile2.wav")
elsif choice2 = "n" then
    put "kk"
end if
if choice1 = "n" then
    put "Fine then! " ..
    delay (1000)
    put "Be that way!"
end if


but when you answer n to the first question it goes on and asks you if you want to change the song which it only should do if you answer y to the first question... how can i get it so if u answer n to the first question it skips the do you want to change songs question and goes right to "Fine Then! Be that way!" ??? Confused
ssr




PostPosted: Tue Feb 15, 2005 9:17 pm   Post subject: (No subject)

use
code:
elsif
instead of Very Happy
code:
if
or
put the ifs inside another if
I think thats called nested ifs
lol
Very Happy gl Very Happy
ssr




PostPosted: Tue Feb 15, 2005 9:21 pm   Post subject: (No subject)

code:
var choice1 : string
var choice2 : string
put "do you want to listen to music? (y or n)"
get choice1
if choice1 = "y" then
    put "ok"
    delay (1000)
    var i : int := 0
    Music.PlayFileLoop ("shortfile1.wav")
    delay (7000)
    %don't end it just there furthermore u will ask the question if the answer is yes
    put "do you want to change songs (y or n)?"
    get choice2
    if choice2 = "y" then
        put "changing..."
        delay (1000)
        var j : int := 0
        Music.PlayFileLoop ("shortfile2.wav")
    elsif choice2 = "n" then
        put "kk"
    end if
elsif choice1 = "n" then
    put "Fine then! " ..
    delay (1000)
    put "Be that way!"
end if

There you go, a code, hopefully thats what u need Very Happy Very Happy
ssr




PostPosted: Tue Feb 15, 2005 9:23 pm   Post subject: (No subject)

Or I know that people say
code:
process
is evil
but I do suggest using it in a music file
so u can get the input while the music is playing

Check out the tutorial if u dont know what a
code:
process
is.
Very Happy Very Happy
Im sure there are better ways to do it.
Good Luck With It Very Happy Very Happy 8)
DVL_IAC




PostPosted: Tue Feb 15, 2005 10:18 pm   Post subject: (No subject)

ssr wrote:
code:
var choice1 : string
var choice2 : string
put "do you want to listen to music? (y or n)"
get choice1
if choice1 = "y" then
    put "ok"
    delay (1000)
    var i : int := 0
    Music.PlayFileLoop ("shortfile1.wav")
    delay (7000)
    %don't end it just there furthermore u will ask the question if the answer is yes
    put "do you want to change songs (y or n)?"
    get choice2
    if choice2 = "y" then
        put "changing..."
        delay (1000)
        var j : int := 0
        Music.PlayFileLoop ("shortfile2.wav")
    elsif choice2 = "n" then
        put "kk"
    end if
elsif choice1 = "n" then
    put "Fine then! " ..
    delay (1000)
    put "Be that way!"
end if

There you go, a code, hopefully thats what u need Very Happy Very Happy


yay it worked! Very Happy TY!
DVL_IAC




PostPosted: Tue Feb 15, 2005 10:25 pm   Post subject: (No subject)

Now 1 more question and i think i should be good for a bit Posted Image, might have been reduced in size. Click Image to view fullscreen. can you make like a go back button... like if u asked what do u want to do and they select play games which brings up a list of games they can play and 1 option would be go back to main menu... is there a code to go back one step? Confused

[edit]
woah regular users can double post! Posted Image, might have been reduced in size. Click Image to view fullscreen. in the forums i usually hang around at only staff and admins can double post. Posted Image, might have been reduced in size. Click Image to view fullscreen. if regular users could double post the forums would get majorly spammed up Posted Image, might have been reduced in size. Click Image to view fullscreen.
ssr




PostPosted: Wed Feb 16, 2005 12:20 pm   Post subject: (No subject)

yes sure u can
put the code in a
code:
loop
and after the programis finished, get the input from the user, use if statement again to check if they want to continue...I think thats it.


Quote:
woah regular users can double post! in the forums i usually hang around at only staff and admins can double post. if regular users could double post the forums would get majorly spammed up


As for that yaya we all should be greatful for that
lol Very Happy Very Happy
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 2  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: