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

Username:   Password: 
 RegisterRegister   
 Letters going up
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Finaltank




PostPosted: 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

code:

A
B
C
D
E
... (all the way to)
Z


or

code:

AA
AB
AC
AD
... (all the way to)
ZZ
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Mon Oct 10, 2005 1:31 pm   Post subject: (No subject)

Well ill show you the LONG way...

code:

var let: array 1 .. 26 of string

for i: 2 .. 26
    let(1) := "A"
    let(2) := "B"
    let(3) := "C"
    let(4) := "D"
    let(5) := "E"
    let(6) := "F"
    let(7) := "G"
    let(8) := "H"
    let(9) := "I"
    let(10) := "J"
    let(11) := "K"
    let(12) := "L"
    let(13) := "M"
    let(14) := "N"
    let(15) := "O"
    let(16) := "P"
    let(17) := "Q"
    let(18) := "R"
    let(19) := "S"
    let(20) := "T"
    let(21) := "U"
    let(22) := "V"
    let(23) := "W"
    let(24) := "X"
    let(25) := "Y"
    let(26) := "Z"
end for

for i: 1 .. 26
    put let(i), "   " ..
end for


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??
Cervantes




PostPosted: Mon Oct 10, 2005 1:46 pm   Post subject: (No 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.
Cervantes




PostPosted: Mon Oct 10, 2005 1:57 pm   Post subject: (No 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:
code:

const base := 26

for i : 1 .. 26**2
    put intstr (i, 0, base)
end for

Now, you just need to use some string manipulation to convert that to all letters.
codemage




PostPosted: Tue Oct 11, 2005 8:17 am   Post subject: (No subject)

Quote:
Also, look up ord and chr


Fastest/easiest way, IMHO.
These functions convert numbers to letters & vice-versa.

code:
put chr ((ord ("a") + 1))

this code will output the letter "b"

Note - the letter "Z" will be a special case if you do it this way.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: