
-----------------------------------
DVL_IAC
Sat Feb 12, 2005 11:38 pm

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:

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?  :?   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 http://www.levels4you.com/graphics/smilies/tongue.gif

-----------------------------------
Tony
Sat Feb 12, 2005 11:48 pm


-----------------------------------
you could build out [url=http://www.compsci.ca/v2/viewtopic.php?t=367]if - elsif - else structure.

-----------------------------------
1337_brad
Sun Feb 13, 2005 12:21 am

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
Sun Feb 13, 2005 10:32 pm


-----------------------------------
you could build out 

i clicked the link and read and im confused. http://www.levels4you.com/graphics/smilies/tongue.gif

i put
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!" http://www.levels4you.com/graphics/smilies/tongue.gif

i'm guessing im not understanding the if - elsif - else thing right http://www.levels4you.com/graphics/smilies/tongue.gif

-----------------------------------
cycro1234
Mon Feb 14, 2005 8:26 am


-----------------------------------
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
Mon Feb 14, 2005 10:31 am


-----------------------------------
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 :lol: 

Use F2 to indent your code and take a look at your structure closely. Try to follow it through in your head.

-----------------------------------
DVL_IAC
Mon Feb 14, 2005 5:30 pm


-----------------------------------
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

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


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.  


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... :?

-----------------------------------
Bacchus
Mon Feb 14, 2005 5:39 pm


-----------------------------------
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"

-----------------------------------
DVL_IAC
Tue Feb 15, 2005 6:20 pm


-----------------------------------
ok i got it to continue when you push n on the first question.. :) 


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!" ??? :?

-----------------------------------
ssr
Tue Feb 15, 2005 9:17 pm


-----------------------------------
use elsif instead of  :D ifor
put the ifs inside another if
I think thats called nested ifs 
lol
 :D gl :D

-----------------------------------
ssr
Tue Feb 15, 2005 9:21 pm


-----------------------------------
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 :D  :D

-----------------------------------
ssr
Tue Feb 15, 2005 9:23 pm


-----------------------------------
Or I know that people say 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 process is.
 :D  :D 
Im sure there are better ways to do it.
Good Luck With It :D  :D  8)

-----------------------------------
DVL_IAC
Tue Feb 15, 2005 10:18 pm


-----------------------------------
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 :D  :D

yay it worked! :D TY!

-----------------------------------
DVL_IAC
Tue Feb 15, 2005 10:25 pm


-----------------------------------
Now 1 more question and i think i should be good for a bit http://www.levels4you.com/graphics/smilies/tongue.gif 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? :?

http://www.levels4you.com/graphics/smilies/tongue.gif in the forums i usually hang around at only staff and admins can double post. http://www.levels4you.com/graphics/smilies/tongue.gif if regular users could double post the forums would get majorly spammed up http://www.levels4you.com/graphics/smilies/tongue.gif

-----------------------------------
ssr
Wed Feb 16, 2005 12:20 pm


-----------------------------------
yes sure u can 
put the code in a 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.


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 :D  :D

-----------------------------------
Tony
Wed Feb 16, 2005 1:11 pm


-----------------------------------
woah regular users can double post! http://www.levels4you.com/graphics/smilies/tongue.gif in the forums i usually hang around at only staff and admins can double post. http://www.levels4you.com/graphics/smilies/tongue.gif if regular users could double post the forums would get majorly spammed up http://www.levels4you.com/graphics/smilies/tongue.gif
If you intend to spam, you'll be in for a surprise :twisted:

-----------------------------------
DVL_IAC
Wed Feb 16, 2005 8:53 pm


-----------------------------------
yes sure u can 
put the code in a 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

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? :?  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? :?

-----------------------------------
ssr
Wed Feb 16, 2005 8:56 pm


-----------------------------------
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. :D  :D

-----------------------------------
ssr
Wed Feb 16, 2005 8:58 pm


-----------------------------------
made just a very small change c if u can find it and hope it helps
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
 :D  :D

-----------------------------------
Bacchus
Wed Feb 16, 2005 9:15 pm


-----------------------------------
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

-----------------------------------
ssr
Wed Feb 16, 2005 9:25 pm


-----------------------------------
yepyep
didnt pay attention to that part
here is a useable one I hope
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 loop I mean put teh whole thing, not just a loop end loop
 :lol:  :D  :D

EDIT
this is the code with a proper indentation
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


-----------------------------------
StarGateSG-1
Thu Feb 17, 2005 12:17 pm


-----------------------------------
I have done you 2 favors here is the program aswell as proper format for code :shock:  :shock:  :shock: 


% 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 :!:  :!:

-----------------------------------
DVL_IAC
Fri Feb 18, 2005 8:32 pm


-----------------------------------



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 :D

I have done you 2 favors here is the program aswell as proper format for code :shock:  :shock:  :shock: 


% 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 :!:  :!:

thanks for the code but ssr already gave me a working code for the music program a page back.. i saved your code though :D i might need to refer back to it sometime :D

% 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 :D

-----------------------------------
DVL_IAC
Fri Feb 18, 2005 9:20 pm


-----------------------------------
Yay I made my first possably useful program http://www.levels4you.com/graphics/smilies/tongue.gif
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 http://www.levels4you.com/graphics/smilies/tongue.gif
its a pretty cheap program but if u want to try it u can d/l it http://www.levels4you.com/graphics/smilies/tongue.gif

-----------------------------------
ssr
Sat Feb 19, 2005 1:59 pm


-----------------------------------
Its a nice program, but it would be better if the user can chaneg teh ratio of teh currency, since its always changing. 
 :D  :D 
gj
