Computer Science Canada help wth input |
Author: | q753951 [ 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 |
Author: | Tony [ 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. |
Author: | The_Bean [ 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. |
Author: | Euphoracle [ 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 |
Author: | q753951 [ 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? |
Author: | The_Bean [ Thu Jan 15, 2009 10:46 pm ] | ||
Post subject: | Re: help wth input | ||
You can use:
|