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

Username:   Password: 
 RegisterRegister   
 inclusive if statements
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
blankout




PostPosted: Tue Apr 14, 2009 3:36 pm   Post subject: inclusive if statements

I was wondering is it's possible to have an if statement that is inclusive, such as

Turing:

if answer="y"
then
%...


is it possible to have the user input a word and as long as the word has the letter y in it, the program will run a specific output?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Apr 14, 2009 3:46 pm   Post subject: RE:inclusive if statements

you might be interested in index
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
blankout




PostPosted: Tue Apr 14, 2009 3:54 pm   Post subject: Re: inclusive if statements

so i tried using index, but i don't quite get it, if you can understand what i'm trying to do from this code, can i get any help?

Turing:

var word : string
get word : *
cls
put index (word, "a")
cls
if index (word, "a") then
put word(1..index(word, "a")-1)..
put "i"(index(word, "a")..length (word))
end if
Tony




PostPosted: Tue Apr 14, 2009 4:07 pm   Post subject: RE:inclusive if statements

index returns an integer value, not boolean (true/false).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TheGuardian001




PostPosted: Tue Apr 14, 2009 4:07 pm   Post subject: Re: inclusive if statements

the index command returns an integer value based on where the letter was found in the string, or 0 if the letter was not found. so if we only need to know if the letter was found, what result would we check for?

Edit: Ninja'd by Tony.
blankout




PostPosted: Tue Apr 14, 2009 4:09 pm   Post subject: Re: inclusive if statements

well i'm trying to replace all 'a' s in a sentence with 'i's, so what would i need to do in order to produce that result
Tony




PostPosted: Tue Apr 14, 2009 4:37 pm   Post subject: RE:inclusive if statements

Start with simplifying the problem. Your teacher might have been saying something like that -- breaking problems down into smaller problems. "Command & Conquer", or something lame like that.

My favourite approach to such problems is recursion / induction.

All you have to do is figure out two things:
1. What is the most basic case for this problem.
2. How can you get one step closer to such a base case.

And those two steps are enough for any size of a problem, 1 to infinity (limited by hardware and time Wink )


1. What is the shortest sentence you can think of, where you would need to replace 'a'?
2. Given a sentence of any length (longer than one in #1), how can you get it to be one letter shorter?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: