help on reading

This is a discussion on help on reading within the C++ Programming forums, part of the General Programming Boards category; i'm suppose to enter random numbers and try to read them one by one and print them out etc enter ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    help on reading

    i'm suppose to enter random numbers and try to read them one by one and print them out

    etc


    enter number : 56124

    your first number is 5

    third number is 1

    and last number 4

    how should i go about reading them?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    Read them into a string, or character by character.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    but it has to be done in int format so that i can do some math with it

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    take for example i input random number 54823

    i got to read the number here

    and do some math to find out how many even number is there here

    how do i go about reading the numbers individualy so that i could do some math to each

    number alone

    between they are all int

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Let's say the user entered 52314.

    If you wanted to work right to left, you could take the remainder after dividing by 10 and that would give you 4. Doing it again would give you 1, then 3, then 2 then 5, and you would then stop because your number remaining would be 0.

    If you wanted to work left to right, you could determine, in a loop, the power of 10 the number adheres to. In this case, it would be 10,000. Dividing by 10,000 would give you 5. Then, subtract out 50,000, reduce the power of 10 by one to give yourself 1,000 and divide 2,314 by that. That would give you 2. And, so on.

    Todd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  2. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  3. Replies: 2
    Last Post: 01-28-2008, 03:07 AM
  4. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 09:39 AM
  5. file reading
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2002, 11:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21