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

Username:   Password: 
 RegisterRegister   
 help with the index!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DBZ




PostPosted: Thu Dec 25, 2003 7:25 pm   Post subject: help with the index!!

Guys, i need help with the following program! U see the program is suppose to replace the letter in a word with another letter. This program i have made so far, only replaces one letter in the word if there are two same letters. For example, If i have entered the word "Banana" and then if i have enetered the patern "a" then the replacement pattern"o". it is suppose to output he word "Bonono". but it doesn't do that! please help! thanx! Please enter ur suggestions in the program and repost it here!

Here is the program:

var word, pattern,replacement:string
var pos:int
put"Enter the word: "..
get word
put"Enter the pattern: "..
get pattern
put "Enter replacement: "..
get replacement


word:=word(1..(index(word,pattern)-1))+ replacement+word((index(word,pattern)+1)..*)

put word
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Dec 25, 2003 7:31 pm   Post subject: (No subject)

oh, boo hoo Confused

that's because you replace only once. You need to have that in the loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DBZ




PostPosted: Thu Dec 25, 2003 7:36 pm   Post subject: (No subject)

Tony, i don't get it! could u please be more specific? thanx!
Tony




PostPosted: Fri Dec 26, 2003 1:42 am   Post subject: (No subject)

you see how you got this

index + replace + index ?

well as you said it yourself, what if replace would have to be in more place then one (2+ letters/patterns). That would have to make it

index + replace + index + replace + index...

but since you dont know what crazy thing the user will enter, you'd have to make a loop that follows in that pattern.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: