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

Username:   Password: 
 RegisterRegister   
 Siri-like Program Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DaBigOne




PostPosted: Wed Dec 04, 2013 5:47 pm   Post subject: Siri-like Program Help

What is it you are trying to achieve?
Trying to make a Siri-like program which can detect a specific word in a string, and return an appropriate result.

What is the problem you are having?

I can make Turing search for the string and detect whether it is there, but I don?t know how to add an if command to this, so if it detects a specific word, it will do a specific action.

Describe what you have tried to solve this problem

I?ve tried adding an if command to the index, but it gives me an error.

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

Turing:


var weather : string := "weather"
var phrase : string

put "Hello. How can I help you?"
get phrase : *
put "You asked for weather at: ",

index (phrase, weather)



Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Wed Dec 04, 2013 10:48 pm   Post subject: RE:Siri-like Program Help

Ok, all index does is return a number for you. If it is in the string, it returns the position of the pattern inside the string. If it's not in the string, it will return zero. Eg index("hello", "el") returns 2, but index("hello", "a") returns zero. So you can do something like this:

if index(input, stringYoureLookingFor) > 0 then
do something
end if
DaBigOne




PostPosted: Wed Dec 04, 2013 11:13 pm   Post subject: Re: Siri-like Program Help

Ah, the solution seems so obvious now.
Thank you Smile
Raknarg




PostPosted: Thu Dec 05, 2013 12:13 am   Post subject: RE:Siri-like Program Help

anytime (Y)
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  [ 4 Posts ]
Jump to:   


Style:  
Search: