Computer Science Canada Letters going up |
Author: | Finaltank [ Mon Oct 10, 2005 11:24 am ] | ||||
Post subject: | Letters going up | ||||
How would you make letters increase? Ex: A + 1 = B? array of 1..26? For an example: I want my output to be
or
|
Author: | TokenHerbz [ Mon Oct 10, 2005 1:31 pm ] | ||
Post subject: | |||
Well ill show you the LONG way...
Of course you DONT want to do this with AA-ZZ, so heres a hint.. Each letter has a number variable, and theres ALWAYS an easier way to creat somthing... I dont want to give you the code for this, cause i think its for your homework, BUT, the abouve is just an example of how things would work, but imagine if there was a number... which reprsents the letter, without having to declare the letter?? |
Author: | Cervantes [ Mon Oct 10, 2005 1:46 pm ] |
Post subject: | |
Tokenherbz, why would you iterate from 2 to 26 in that initial for loop when you don't even use the index? You're just erasing values over and over again and rewriting them with the same values. Finaltank, pretend you're counting in Base 26. Also, look up ord and chr. There's a section in the String Manipulation tutorial. |
Author: | Cervantes [ Mon Oct 10, 2005 1:57 pm ] | ||
Post subject: | |||
Cervantes wrote: Finaltank, pretend you're counting in Base 26.
In case you didn't know, you can use intstr to work in different bases:
Now, you just need to use some string manipulation to convert that to all letters. |
Author: | codemage [ Tue Oct 11, 2005 8:17 am ] | ||
Post subject: | |||
Quote: Also, look up ord and chr
Fastest/easiest way, IMHO. These functions convert numbers to letters & vice-versa.
this code will output the letter "b" Note - the letter "Z" will be a special case if you do it this way. |