count digits

This is a discussion on count digits within the C++ Programming forums, part of the General Programming Boards category; Hi, This is my first post, and if you read my bio you'll see I'm only taking an intro class. ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    4

    count digits

    Hi,

    This is my first post, and if you read my bio you'll see I'm only taking an intro class.

    I'm trying to find a function that will read digits of an int, but only a certain type (i.e. only the zeroes, or 4's, or whatever).

    Another question: is there a way to read an integer right to left?

    Thanks.

    -->Mariana

    p.s. Yes, this is for an assignment, but I just want a hint or push in the right direction, not the whole thing done for me.

  2. #2
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    i suggest reading the input as a string and then doing what you must with it like reversing , extracting specific digits etc.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you could also try using modulo since you're using ints...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by major_small
    you could also try using modulo since you're using ints...
    Yes, using modulo effectively will 'read' get each digit from right to left.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    what is modulo ????

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what is modulo ????
    The % operator. It calculates the remainder of a division.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    Originally posted by Prelude
    >what is modulo ????
    The % operator. It calculates the remainder of a division.
    oh .. yes thanks and sorry i use it without knowing its name

  8. #8
    Registered User
    Join Date
    Feb 2004
    Posts
    4
    Originally posted by major_small
    you could also try using modulo since you're using ints...
    Thank you! I was racking my brains for a while, then it clicked.

    I know it as modulus, but it's all the same.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bintree and count (withouth using template)?
    By cubimongoloid in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2009, 06:22 AM
  2. Count the number of vowels, consonants, digits etc.
    By kumar14878 in forum C Programming
    Replies: 3
    Last Post: 05-09-2005, 12:34 AM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Count Number of Digits in and Integer
    By redneon in forum C++ Programming
    Replies: 2
    Last Post: 08-18-2003, 04:16 PM
  5. Replies: 3
    Last Post: 11-17-2002, 03:51 PM

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