Computer Science Canada

Question in a question

Author:  DVL_IAC [ 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.

Author:  Tony [ Sat Feb 12, 2005 11:48 pm ]
Post subject: 

you could build out if - elsif - else structure.

Author:  1337_brad [ 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]

Author:  DVL_IAC [ Sun Feb 13, 2005 10:32 pm ]
Post 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.

Author:  cycro1234 [ Mon Feb 14, 2005 8:26 am ]
Post 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.

Author:  Tony [ Mon Feb 14, 2005 10:31 am ]
Post 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.

Author:  DVL_IAC [ Mon Feb 14, 2005 5:30 pm ]
Post 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

Author:  Bacchus [ Mon Feb 14, 2005 5:39 pm ]
Post 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"

Author:  DVL_IAC [ Tue Feb 15, 2005 6:20 pm ]
Post 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

Author:  ssr [ Tue Feb 15, 2005 9:17 pm ]
Post 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

Author:  ssr [ Tue Feb 15, 2005 9:21 pm ]
Post 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

Author:  ssr [ Tue Feb 15, 2005 9:23 pm ]
Post 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)

Author:  DVL_IAC [ Tue Feb 15, 2005 10:18 pm ]
Post 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!

Author:  DVL_IAC [ Tue Feb 15, 2005 10:25 pm ]
Post 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.

Author:  ssr [ Wed Feb 16, 2005 12:20 pm ]
Post 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

Author:  Tony [ Wed Feb 16, 2005 1:11 pm ]
Post subject: 

DVL_IAC wrote:
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.

If you intend to spam, you'll be in for a surprise Twisted Evil

Author:  DVL_IAC [ Wed Feb 16, 2005 8:53 pm ]
Post subject: 

ssr wrote:
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.


Hmm I can't figure out whats wrong
code:

var choice1 : string
var choice2 : string
var choice3 : string
put "What do you want to do?"
put "I=Internet, P=Process"
get choice1
if choice1 = "I" then
    put "Where do you want to go? (G=good gaming site, C=good programming site, B=back)"
    get choice2
    if choice2 = "G" then
        if not Sys.Exec ("http://www.levels4you.com/") then
            put "The Sys.Exec call failed"
            put "Error: ", Error.LastMsg
        elsif choice2 = "C" then
            if not Sys.Exec ("http://www.compsci.ca/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            elsif choice2 = "B" then
                loop
                end loop
            end if
        elsif choice1 = "P" then
            put "What do you wanna do? (P=Process, B=back)"
            get choice3
            if choice3 = "P" then
                put "processing"
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "."
                delay (1000)
                put "uhh"
                delay (2000)
                put "you choose to process"
            elsif choice3 = "B" then
                loop
                end loop
            end if
        end if
    end if
end if


if i choose I for the first question then choose C or B for the second question it just finishes the program and doesnt do anything and if i choose P for the first question the program just finishes and doesnt bring up P's options... what am I doing wrong? Confused also when i choose I for the first question and G for the second it works but then just finishes the program. how can i make it so it automatically goes back 1 step so when your done with the choice you can continue the program insted of having to re start? Confused

Author:  ssr [ Wed Feb 16, 2005 8:56 pm ]
Post subject: 

I just looked at ur code and the problem is
u for got to end if
see teh indentations?
the elsi fto get p is not in teh loop u wants it to be in. Very Happy Very Happy

Author:  ssr [ Wed Feb 16, 2005 8:58 pm ]
Post subject: 

made just a very small change c if u can find it and hope it helps
code:
var choice1 : string
var choice2 : string
var choice3 : string
put "What do you want to do?"
put "I=Internet, P=Process"
get choice1
if choice1 = "I" then
    put "Where do you want to go? (G=good gaming site, C=good programming site, B=back)"
    get choice2
    if choice2 = "G" then
        if not Sys.Exec ("http://www.levels4you.com/") then
            put "The Sys.Exec call failed"
            put "Error: ", Error.LastMsg
        end if
    elsif choice2 = "C" then
        if not Sys.Exec ("http://www.compsci.ca/") then
            put "The Sys.Exec call failed"
            put "Error: ", Error.LastMsg
        elsif choice2 = "B" then
            loop
            end loop
        end if
    elsif choice1 = "P" then
        put "What do you wanna do? (P=Process, B=back)"
        get choice3
        if choice3 = "P" then
            put "processing"
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "."
            delay (1000)
            put "uhh"
            delay (2000)
            put "you choose to process"
        elsif choice3 = "B" then
            loop
            end loop
        end if
    end if
end if
Very Happy Very Happy

Author:  Bacchus [ Wed Feb 16, 2005 9:15 pm ]
Post subject: 

ur back buttons still arnt working cause when you cxhoose them it enters a loop then just repeats in that loop never to end.... not what u want
what you want to do is start the loop where you want it to go back to and put the end loop after all of that and since im guessing that whatever you do it will go back to the beginning just stil the whole chioce thing in a loop-end loop

Author:  ssr [ Wed Feb 16, 2005 9:25 pm ]
Post subject: 

yepyep
didnt pay attention to that part
here is a useable one I hope
code:
var choice1 : string
var choice2 : string
var choice3 : string

loop
    put "What do you want to do?"
    put "I=Internet, P=Process"
    get choice1

    if choice1 = "I" then
        put "Where do you want to go? (G=good gaming site, C=good programming site, B=back)"
        get choice2
        if choice2 = "G" then
            if not Sys.Exec ("http://www.levels4you.com/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        elsif choice2 = "C" then
            if not Sys.Exec ("http://www.compsci.ca/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        end if
        end if
loop
    if choice1 = "P" then
        put "What do you wanna do? (P=Process, B=back)"
        get choice3
        if choice3 = "P" then
            put "processing"
            for i : 1 .. 10
                delay (1000)
                put "."..
            end for
            put "uhh"
            delay (2000)
            put "you choose to process"
        end if
        if choice3 = "B"
        then exit
        end if
        end if
    end loop
end loop

You know when I say put it in a
code:
loop
I mean put teh whole thing, not just a
code:
loop end loop

Laughing Very Happy Very Happy

EDIT
this is the code with a proper indentation
code:
var choice1 : string
var choice2 : string
var choice3 : string

loop
    put "What do you want to do?"
    put "I=Internet, P=Process"
    get choice1

    if choice1 = "I" then
        put "Where do you want to go? (G=good gaming site, C=good programming site, B=back)"
        get choice2
        if choice2 = "G" then
            if not Sys.Exec ("http://www.levels4you.com/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        elsif choice2 = "C" then
            if not Sys.Exec ("http://www.compsci.ca/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        end if
    end if
    loop
        if choice1 = "P" then
            put "What do you wanna do? (P=Process, B=back)"
            get choice3
            if choice3 = "P" then
                put "processing"
                for i : 1 .. 10
                    delay (1000)
                    put "." ..
                end for
                put "uhh"
                delay (2000)
                put "you choose to process"
            end if
            if choice3 = "B"
                    then
                exit
            end if
        end if
    end loop
end loop

Author:  StarGateSG-1 [ Thu Feb 17, 2005 12:17 pm ]
Post subject: 

I have done you 2 favors here is the program aswell as proper format for code Shocked Shocked Shocked

code:

% StargateSG-1 (aka chris harshman) (your name)
% Febuary 17, 2005 (date)
% Myself and others (who it is for)
% This is a program to play music files (brief description

% This is my version of your assignment
% It is more professial and covers all the basic's you will
% learn through the year

% Notes for beginner:
% Never use delays unless you must
% Use the "press any key"
% Use processes for music and other things like saving
% Use procedures for everything else (make sure to use foward)
% Document your program
% Make your program user friendly
% YOu can use shorthand for documenting
% It is for your eyes only
% Make a header
% Include variable dictionary
% Any other questions just P.M. me

% Declaration of Variables
var choice : char

% Variables Dictionary
% choice - type = char/gets input from user

% Calls procedures
forward procedure first_music_play
forward procedure second_music_play
forward procedure main

% Processes for music files
% First music file
process first_music_file
    Music.PlayFileLoop ("music file name")
end first_music_file

% Seconf music file
process second_music_file
    Music.PlayFileLoop ("music file name")
end second_music_file

% Playing first music file
body procedure first_music_play
    % Calls music file
    fork first_music_file
    % Asks for a change in songs
    put "press any key to change songs"
    loop
        if hasch then
            exit
        end if
    end loop
    second_music_play
end first_music_play

% Playing second music file
body procedure second_music_play
    % Ask user what to do
    put "do you want to change songs (Y/N)?"
    get choice
    if choice = "y" or choice = "Y" then
        %Tells user what program is doing
        % Loading screen
        put "Changing song" ..
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        % Calls music file
        fork second_music_file
    else
        put "Ok have it your way"

    end if
end second_music_play

% Main procedure
body procedure main
    % Asks user what to do
    put "do you want to listen to music (Y/N)?"
    get choice
    if choice = "y" or choice = "Y" then
        % Loading screen
        put "Loading music" ..
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        first_music_play
    else
        put "Quiting Program Now"
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        quit
    end if
end main

% Starts program
main

Good luck with it Exclamation Exclamation

Author:  DVL_IAC [ Fri Feb 18, 2005 8:32 pm ]
Post subject: 

ssr wrote:


code:

var choice1 : string
var choice2 : string
var choice3 : string
loop
    put "What do you want to do?"
    put "I=Internet, P=Process"
    get choice1
    if choice1 = "I" then
        put "Where do you want to go? (G=good gaming site, C=good programming site, B=back)"
        get choice2
        if choice2 = "G" then
            if not Sys.Exec ("http://www.levels4you.com/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        elsif choice2 = "C" then
            if not Sys.Exec ("http://www.compsci.ca/mx/") then
                put "The Sys.Exec call failed"
                put "Error: ", Error.LastMsg
            end if
        end if
    end if
end loop
loop
    if choice1 = "P" then
        put "What do you wanna do? (P=Process, B=back)"
        get choice3
        if choice3 = "P" then
            put "processing"
            for i : 1 .. 10
                delay (1000)
                put "." ..
            end for
            put "uhh"
            delay (2000)
            put "you choose to process"
        end if
        if choice3 = "B"
                then
            exit
        end if
    end if
end loop


i just had to move one of the end loops and it works fine Very Happy

StarGateSG-1 wrote:
I have done you 2 favors here is the program aswell as proper format for code Shocked Shocked Shocked

code:

% StargateSG-1 (aka chris harshman) (your name)
% Febuary 17, 2005 (date)
% Myself and others (who it is for)
% This is a program to play music files (brief description

% This is my version of your assignment
% It is more professial and covers all the basic's you will
% learn through the year

% Notes for beginner:
% Never use delays unless you must
% Use the "press any key"
% Use processes for music and other things like saving
% Use procedures for everything else (make sure to use foward)
% Document your program
% Make your program user friendly
% YOu can use shorthand for documenting
% It is for your eyes only
% Make a header
% Include variable dictionary
% Any other questions just P.M. me

% Declaration of Variables
var choice : char

% Variables Dictionary
% choice - type = char/gets input from user

% Calls procedures
forward procedure first_music_play
forward procedure second_music_play
forward procedure main

% Processes for music files
% First music file
process first_music_file
    Music.PlayFileLoop ("music file name")
end first_music_file

% Seconf music file
process second_music_file
    Music.PlayFileLoop ("music file name")
end second_music_file

% Playing first music file
body procedure first_music_play
    % Calls music file
    fork first_music_file
    % Asks for a change in songs
    put "press any key to change songs"
    loop
        if hasch then
            exit
        end if
    end loop
    second_music_play
end first_music_play

% Playing second music file
body procedure second_music_play
    % Ask user what to do
    put "do you want to change songs (Y/N)?"
    get choice
    if choice = "y" or choice = "Y" then
        %Tells user what program is doing
        % Loading screen
        put "Changing song" ..
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        % Calls music file
        fork second_music_file
    else
        put "Ok have it your way"

    end if
end second_music_play

% Main procedure
body procedure main
    % Asks user what to do
    put "do you want to listen to music (Y/N)?"
    get choice
    if choice = "y" or choice = "Y" then
        % Loading screen
        put "Loading music" ..
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        first_music_play
    else
        put "Quiting Program Now"
        for i : 1 .. 5
            put "." ..
            delay (500)
        end for
        cls
        quit
    end if
end main

% Starts program
main

Good luck with it Exclamation Exclamation


thanks for the code but ssr already gave me a working code for the music program a page back.. i saved your code though Very Happy i might need to refer back to it sometime Very Happy
Quote:

% This is my version of your assignment
% It is more professial and covers all the basic's you will
% learn through the year

BTW non of these things are assignments.. i just thought of things i wanna find out how to do in turing then made these little example programs where i would need to use them then i can refer back to them Very Happy

Author:  DVL_IAC [ Fri Feb 18, 2005 9:20 pm ]
Post subject: 

Yay I made my first possably useful program Posted Image, might have been reduced in size. Click Image to view fullscreen.
all it does is convert a us price to canadian or a canadian price to us and if u want it'll tell you what the tax would be on something thats the price u choose Posted Image, might have been reduced in size. Click Image to view fullscreen.
its a pretty cheap program but if u want to try it u can d/l it Here Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  ssr [ Sat Feb 19, 2005 1:59 pm ]
Post subject: 

Its a nice program, but it would be better if the user can chaneg teh ratio of teh currency, since its always changing.
Very Happy Very Happy
gj


: