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

Username:   Password: 
 RegisterRegister   
 Problem with Code - Help Please
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Namis




PostPosted: 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
Sponsor
sponsor
Namis




PostPosted: 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




PostPosted: 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




PostPosted: Thu Sep 11, 2003 6:11 pm   Post subject: Thanks

Much Appreciated, ill give it a try now
Namis




PostPosted: 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




PostPosted: 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




PostPosted: 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 Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
krishon




PostPosted: Thu Sep 11, 2003 6:23 pm   Post subject: (No subject)

lol, i beat u to it Laughing
Dan




PostPosted: Thu Sep 11, 2003 6:25 pm   Post subject: (No subject)

ya i know Hit Wall
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Namis




PostPosted: 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




PostPosted: 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




PostPosted: 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 Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
krishon




PostPosted: Thu Sep 11, 2003 6:55 pm   Post subject: (No subject)

isnt' return c++??
Tony




PostPosted: 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".

if you want program to close, use
code:

quit

instead
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
krishon




PostPosted: Thu Sep 11, 2003 7:00 pm   Post subject: (No subject)

oh ok
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 3  [ 35 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: