Posted: Thu Sep 11, 2003 2:56 pm Post subject: Problem with Code - Help Please
var one : string
var two : string
put " Yes or No? "
if one = "Yes" then
put " Good Choice! "
elsif two = "No" then
put " Bad Choice! "
im getting 1 error, what is wrong with this?
Sponsor Sponsor
Namis
Posted: Thu Sep 11, 2003 3:20 pm Post subject: Different Code
put " hello " ..
put " What is your name? "
put " my name is Andrew. "
put " How are you today? "
var fine : string
get fine
put " Well, Im doing Good " ..
put " Not exactly ", fine ..
put " though "
var game : string
var Yes : string
put " Want to play a game? " ..
put " Yes or No "
get game
if game = Yes then
put " Cool, lets play a game! "
else
put " Ok You dont want to play a game then "
end if
- OK This code works fine, but after user answers Yes/No, it finishes the program without saying " Lets play, or OK you dont want to play "
What am i doing wrong?? Any Help would be appreciated
Archi
Posted: Thu Sep 11, 2003 4:01 pm Post subject: (No subject)
When using if statements involving variables which are strings u need to include the " "....So the code for this which works will be:
put " hello " ..
put " What is your name? "
put " my name is Andrew. "
put " How are you today? "
var fine : string
get fine
put " Well, Im doing Good " ..
put " Not exactly ", fine ..
put " though "
var game : string
var Yes : string
put " Want to play a game? " ..
put " Yes or No "
get game
if game = "Yes" then
put " Cool, lets play a game! "
else
put " Ok You dont want to play a game then "
end if[/b]
Namis
Posted: Thu Sep 11, 2003 6:11 pm Post subject: Thanks
Much Appreciated, ill give it a try now
Namis
Posted: Thu Sep 11, 2003 6:18 pm Post subject: (No subject)
This is what i got now, It works fine ( if i take the "No" Part out. )
[/code]put " hello " ..
put " What is your name? "
put " my name is Andrew. "
put " How are you today? "
var fine : string
get fine
put " Well, Im doing Good " ..
put " Not exactly ", fine ..
put " though "
var game : string
put " Want to play a game? " ..
put " Yes or No "
get game
if game = "Yes" then
put " Cool, lets play a game! "
elsif No = "No" then <---- Says No = Is An Error
put " Fine, Be that Way "
exit <--- Says Exit is an error.
end if
Anyone know why?
krishon
Posted: Thu Sep 11, 2003 6:20 pm Post subject: (No subject)
instead of doing elsif's all the time, u can do else. Else will take any other value other than yes in ur case and output a message. That way ppl will not hafta type in no all the time. And put ur varialbes at the top...its better that way so u know wut variables u use. This really helps when programs begin to get big
Dan
Posted: Thu Sep 11, 2003 6:22 pm Post subject: (No subject)
i think tony toald you this in another fourm, you need to have a var named No to check if it is equal to "no".
you are geting input in game for this so why not chage the No to game it should wrok.
also you could use an else stamet insted of elsif
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
krishon
Posted: Thu Sep 11, 2003 6:23 pm Post subject: (No subject)
lol, i beat u to it
Sponsor Sponsor
Dan
Posted: Thu Sep 11, 2003 6:25 pm Post subject: (No subject)
ya i know
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Namis
Posted: Thu Sep 11, 2003 6:47 pm Post subject: K
Worked it out except for exit, im still getting an error message for exit
code:
else
put " Fine, Be that Way "
exit <-------- Error
end if
krishon
Posted: Thu Sep 11, 2003 6:52 pm Post subject: (No subject)
exit only works with a loop...u dun't need it in ur program
Dan
Posted: Thu Sep 11, 2003 6:52 pm Post subject: (No subject)
try return, but i think this is bad progaming.
why not just put game code in the "yes" if?
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
krishon
Posted: Thu Sep 11, 2003 6:55 pm Post subject: (No subject)
isnt' return c++??
Tony
Posted: Thu Sep 11, 2003 7:00 pm Post subject: (No subject)
return sends you right to the end of your program... kind of equivalent to C++'s "press any key to quit".