Thread: help on reading

  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
    28,413
    Read them into a string, or character by character.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    Chappell Hill, Texas
    Posts
    2,332
    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, 08:39 AM
  5. file reading
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2002, 11:55 PM