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

Username:   Password: 
 RegisterRegister   
 string to integer?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
noobsauce




PostPosted: Sun Nov 09, 2008 6:24 pm   Post subject: string to integer?

Ok, I am to make a program that askes the user to enter his name and then separate him into 2 catagories according to his first letter of last name. I want to convert the letter into integer and use the ASCII table to find what it is. But i can't convert it to integer...? here is my code so far

code:

var username : string (100)
var counter, lastname: int := 0
put "Please enter you name: "..
get username : *
loop
counter := counter + 1
exit when username(counter) = username(*)   %donno if this works perfectly
end loop
loop
counter := counter - 1
exit when username(counter) = ' '
end loop
put username(counter+1)
lastname := strint (username(counter+1))        %error on this line
put lastname

Is there a special function to do it? I tried to do it directly:
code:

lastname := username(counter+1)

it says error anyways...

Mod Edit: Please remember Code Tags. Thanks
code:
[code]Code here[/code]
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Sun Nov 09, 2008 7:36 pm   Post subject: Re: string to integer?

there is actually a command built into the language used for this.
Turing:

number := ord(letter)
letter := chr(number)

ord goes from a letter to its ASCII character, while chr does the opposite and converts ASCII codes into letters.
noobsauce




PostPosted: Sun Nov 09, 2008 8:35 pm   Post subject: Re: string to integer?

Thanks it works, but how do i fix
code:

exit when username(counter) = username(*)

It doesn't work if the last letter was repeated in the name
pavol




PostPosted: Sun Nov 09, 2008 10:29 pm   Post subject: Re: string to integer?

I am assuming that your code:
Turing:
loop
    counter := counter + 1
    exit when username (counter) = username (*)
end loop

is used for finding the length of the username string. An easier way of doing this is to simply write:
Turing:
counter := length(username)
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: