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

Username:   Password: 
 RegisterRegister   
 help wth input
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
q753951




PostPosted: Thu Jan 15, 2009 9:23 pm   Post subject: help wth input

i rencently recieved an assignent where the user will enter a 8 digit number (ex.12345678) then this program will make this 8 digit number into 4 set of 2 digit number, add them then div 26 and then it will come up with an alphabet letter, 1 = A, 2 = B etc..

i got most the the parts completed alrdy but i need some help with inputing this 8 digit number, i came up with the idea of declaring 4 variable and then ask the user to 4 set of 2 digit but then i can't ensure the user will enter a 2 digit, they might enter a 3, or 4 digit instead. also it looks weird if they have to enter the numbers seperately.

i'm wondering if there's any method to enter 8 numbers at the sametime and still able to make them 4 set and add them

here's an example on how this program will work

1. user enter 8 number
12345678

2.add them in pairs
12+34+56+78

3.get the remainding
(12+34+56+78) div 26

4.get the corresponding letter and add them to the end
ex. 12345678A
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jan 15, 2009 9:57 pm   Post subject: RE:help wth input

you could div / mod by various powers of 10 to split a number into individual digits.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
The_Bean




PostPosted: Thu Jan 15, 2009 10:04 pm   Post subject: Re: help wth input

You could receive the number as a string, split it up by the placements, and use strint () to convert to a number.
Euphoracle




PostPosted: Thu Jan 15, 2009 10:11 pm   Post subject: RE:help wth input

Although you could read the numbers in separately, I would instead read it all in as raw data, and mutate it from there.

My steps would be as follows:

1. Let them enter whatever they want. I don't care if it's 8 numbers or 372 numbers. I'm only going to use the first 8.
1234567890

2. Split them into pairs
{12, 34, 56, 78}

3. Add them
180

4. Divide by 26 using the div operator.
6

5. Find the ord value of 'A', subtract 1, and add it to the quotient, and then chr it. My reasoning for this step is simple that turing has functionality for converting from ascii->text, might as well put it to use! However, ascii doesn't start at A, it starts with a few misc. characters that aren't letters. My solution? Get the ascii value of A, and subtract 1. Subtracting 1 is vital; we are localizing the numbering, so if we just start a A, we make A = 0, when A should be = 1.
F

6. Output the first 8 numbers entered, and then our letter.
12345678F
q753951




PostPosted: Thu Jan 15, 2009 10:27 pm   Post subject: Re: help wth input

The_Bean @ Thu Jan 15, 2009 10:04 pm wrote:
You could receive the number as a string, split it up by the placements, and use strint () to convert to a number.


what command do i use to split it up?
The_Bean




PostPosted: Thu Jan 15, 2009 10:46 pm   Post subject: Re: help wth input

You can use:
Turing:

var stringVar:string
get stringVar
put stringVar(1..2)
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  [ 6 Posts ]
Jump to:   


Style:  
Search: