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

Username:   Password: 
 RegisterRegister   
 Is there any command that could do this
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kman43759




PostPosted: Wed Oct 08, 2014 4:23 pm   Post subject: Is there any command that could do this

What is it you are trying to achieve?

<
I want to know if theres a command that could let me do something like
var ans : string
put "hi"
get ans
if ans = "hey" or "hi" or "hello" or "you" then
put "Whats up?"
end if>


What is the problem you are having?
<Im coding a program kind of like siri and I already explained everything above. The way im doing it is im having a seperate if for if ans = "hi", if ans = "hey, if ans = "hello", and if ans = "yo" and this is making my code really long... I wish I could just shorten this by putting if ans = "hey" or "hi" or "hello" then put "Whats up">


Describe what you have tried to solve this problem
var ans : string
put "hi"
get ans
if ans = "hey" or "hi" or "hello" or "you" then
put "Whats up?"
end if>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<4.1>
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Oct 08, 2014 5:22 pm   Post subject: RE:Is there any command that could do this

you're almost there!

an if statement (see if) is in the form of
code:

if trueFalseExpn then
   statementsAndDeclarations
end if

trueFalseExpn is any expression that returns a value of true or false (also known as boolean).

There is a boolean operator or that takes two boolean values, and also returns a boolean result (true if either one is true).

In your example, "ans = "hey" is a trueFalseExpn, but "hello" is not. You can see the latter if we use only that part
code:

if "hello" then
  ...

doesn't look right.

You can turn all parts into boolean expressions though!
code:

if ans = "hey" or ans = "hi" or ans = "hello" then
  ...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kman43759




PostPosted: Wed Oct 08, 2014 5:36 pm   Post subject: RE:Is there any command that could do this

Thanks a lot! That really made my code alot smaller and easier to navigate
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 1  [ 3 Posts ]
Jump to:   


Style:  
Search: