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

Username:   Password: 
 RegisterRegister   
 friggin program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
qwertyuiop




PostPosted: Mon Dec 18, 2006 6:38 pm   Post subject: friggin program

i am trying to have the user enter a word then i want to create a new string that has substituded the letters of that word to underscores.. i just cant figure it out can someone look through this code and point out my problem please
code:
var puzzle : string
var puzzle2 : string
put "enter puzzle"
get puzzle
for i : 1 .. length (puzzle)
    if i > 65 and i <= 90 then
        puzzle2 := puzzle2 + "_"
    else
        puzzle2 := puzzle2 + puzzle (i)
    end if
end for
put puzzle2
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Mon Dec 18, 2006 6:48 pm   Post subject: (No subject)

Well your code

code:

if i > 65 and i <= 90 then


Look at your "i" var, it will only go up to the length of the puzzle word. If you are trying to get a specific char variable, which is what i think you'r trying to do, then i suggest you look at chr and ord.

If you want to do it the easy way. Make 2 vars. one for your word, and the other created with "_" for each spot in the word.
Clayton




PostPosted: Mon Dec 18, 2006 9:56 pm   Post subject: (No subject)

He did in fact do that TokenHerbz.

code:

var puzzle : string
var puzzle2 : string

Wink

Now, what you need to do is instead of checking the index of your for loop, you need to check the character value is (using the function ord()). That way you can check the value of each character in your "puzzle" string, then, if a character is a letter, add an underscore to puzzle2, otherwise, add the character to puzzle2.
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: