Thread: I really need some help here

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    5

    I really need some help here

    I can't figure this out someone please help me.

    Take an unsigned long variable, ask the user for input. When the input is acquired make pair of numbers from the left to right hand side to give the ASCII value of that pair.

    Example1:
    Input number: 6968676665 (you don’t need to print this, it is just for illustration—69(E), 68(D), 67(C), 66(B), 65(A))
    Output: ABCDE
    Example2 (in case there is one extra digit… just ignore it.)
    Input number: 16968676665
    Output: ABCDE
    Example3 (in case there is just one digit)
    Input number: 6
    Output:

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    So, have you tried anything?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    EDIT: nvm, didn't read properly

  4. #4
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    How are you storing your number...as a string? If that is the case then if you know how to access each element then add those pairing up, in reverse order.

    65 = 107 (taking the ASCII equivalent)

    Then all you will need to do to get the 'A' character is subtract 42 ( the answer to everything!)

    Example:

    Say your number started with 65. Then to print and display the letter 'A', just do something like

    Code:
      printf("%c\n", (number[0] + number[1]) - 42);
    Note: number[] is an array of char. You will need to figure out sizing, initialization and looping logic to complete this.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Oh, that will not work for all letters, but I will leave the logic up to you to account for all 26 letters.

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    5

    hmm

    Quote Originally Posted by BEN10 View Post
    So, have you tried anything?
    I've tried this

    long integer l = getlongnumber()
    while (l >= 10) {
    print ascii(l % 100)
    l /= 100;
    }

    and for right to left (using recursion for fun)

    print_ascii_code(getlonginteger())

    print_ascii_code(long integer l)
    if (l >= 10) {
    print_ascii_code(l / 100)
    print ascii(l % 100)
    }


    can't get it to work

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you actually have something called 'getlongnumber' defined some place? You really would be better off here using a string.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    5
    Quote Originally Posted by quzah View Post
    Do you actually have something called 'getlongnumber' defined some place? You really would be better off here using a string.

    Quzah.

    I'm so lost on this. How would you guys do this?

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know how to work with arrays? There's a FAQ (see the top of the page) on reading lines of input from the user. Read a line of test (your numbers), and convert them to your number/code.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    5

    hmm

    Quote Originally Posted by quzah View Post
    Do you know how to work with arrays? There's a FAQ (see the top of the page) on reading lines of input from the user. Read a line of test (your numbers), and convert them to your number/code.


    Quzah.

    Like I said, I don't even know where to start on this. I'm trying to get this done and for some reason nothing is sticking.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well you could start by helping us help you. One more time: Do you know how to work with arrays?

    Yes - Use an array to read a string from the user, then walk through the array peeling off numbers.
    No - You could something like getchar in a loop, and then just keep track if you've read an even or odd number as you process them. Odd number, treat it is the higher digit of a two digit number (assuming there can't actually be three digit numbers), even, you've got the low digit as well, so do a bit of magic and convert it to a letter.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Jul 2009
    Posts
    5
    Quote Originally Posted by quzah View Post
    Well you could start by helping us help you. One more time: Do you know how to work with arrays?

    Yes - Use an array to read a string from the user, then walk through the array peeling off numbers.
    No - You could something like getchar in a loop, and then just keep track if you've read an even or odd number as you process them. Odd number, treat it is the higher digit of a two digit number (assuming there can't actually be three digit numbers), even, you've got the low digit as well, so do a bit of magic and convert it to a letter.


    Quzah.
    The code I posted above is that not even close?

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Forget code! You're not there yet.

    Post up how YOU would do this job, step by step, in steps that show the logic, ie., pseudo code.

    We'll work it up with you, from that.

  14. #14
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    I somewhat like these types of exercises, similar to solving Sudoku for me. If you can make heads or tails of this code, you are almost there to solve this:

    Code:
    if (number[len - (2 + i)] == 54)
          printf("%c", (number[len - (2 + i)] + number[len - (1 + i)]) - 42);
        if (number[len - (2 + i)] == 55)
          printf("%c", (number[len - (2 + i)] + number[len - (1 + i)]) - 33);
        if (number[len - (2 + i)] == 56)
          printf("%c", (number[len - (2 + i)] + number[len - (1 + i)]) - 24);
        if (number[len - (2 + i)] == 57)
          printf("%c", (number[len - (2 + i)] + number[len - (1 + i)]) - 15);
    A bit cryptic and done a bit on purpose, so know your ASCII values! So wrap this within a loop and see what you get.

  15. #15
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by quzah View Post
    just keep track if you've read an even or odd number as you process them. Odd number, treat it is the higher digit of a two digit number
    what? how does the number being even or odd effect anything?

    EDIT: unless you mean "...keep track if you've read an even or odd number of times..."
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed