Author |
Message |
noobsauce
|
Posted: 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

|
|
 |
TheGuardian001
|
Posted: 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
|
Posted: 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
|
Posted: 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:
|
|
|
|
|
 |
|