Thread: help me plz a c++ question

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    help me plz a c++ question

    write a function that takes an integer value and returns the number of digits,
    for example given the number 7631, the function should return 4.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What idea do you have that you think you could implement to solve this problem?
    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
    Sep 2010
    Posts
    3
    i only need the function not the whole program baby

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That does not change anything. Refer to the homework policy.
    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

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Where in your post are you actually asking a question?

    Oh wait, you are probably one of those lazy ass bastards with delusions of godhood that expects us, your loyal subjects, to follow your every command.

    Well, to clarify things for you, you are not god, and we are not your subjects. Now, go back to your dark little basement and do your own homework. And don't bother asking mummy for cookies, because you won't get any until you put in some effort into solving your problem.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by MWAAAHAAA View Post
    Oh wait, you are probably one of those lazy ass bastards with delusions of godhood that expects us, your loyal subjects, to follow your every command.
    No, he is one of those ass bastards, who know we don't like begging, and create accounts to only pis$ us off.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    We have no idea what type of individual the OP is, so let's stop making assumptions. laserlight already pointed ou the homework policy.
    Now, if the OP wants some help, he/she can read the homework policy and post an attempt that shows that he/she has actually put some effort into this, or intend to. Otherwise, we won't help. Simple as that.
    No need to throw around insults.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by Elysia View Post
    We have no idea what type of individual the OP is
    The commanding tone of the original message and the shameless use of 'baby' in the second one tells me enough, baby.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You are guessing. You have no proof. Therefore, you are rude. An unfortunate thing on many forums, including this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by Elysia View Post
    You are guessing. You have no proof. Therefore, you are rude. An unfortunate thing on many forums, including this.
    Some might consider the OP's posts rude. Then again, some might consider your inane pro-C++ rants rude (actually, I find those quite amusing).
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MWAAAHAAA View Post
    Some might consider the OP's posts rude...
    And some might not. I don't consider the first one rude.
    The second is a little ambiguous. I cannot tell the individuality of someone from merely two replies.

    ..Then again, some might consider your inane pro-C++ rants rude (actually, I find those quite amusing).
    Insane is subjective. Plus I usually don't direct them as insults against people. So really they aren't rude.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Plus I usually don't direct them as insults against people. So really they aren't rude.
    Agreed, that's why I don't consider them rude.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  13. #13
    Registered User
    Join Date
    Mar 2008
    Posts
    36
    Here's a thought. Keep dividing the number by 10 until it goes to zero.

    7631/10 = 763
    763/10 = 76
    76/10 = 7
    7/10 = 0

  14. #14
    Registered User
    Join Date
    Dec 2009
    Posts
    120
    all you have to do is put the number into a string, then print the string.length() function.

    string number;

    getline(cin, number);

    cout << number.length();

  15. #15
    Registered User
    Join Date
    Dec 2009
    Posts
    120
    Quote Originally Posted by rocketman50 View Post
    Here's a thought. Keep dividing the number by 10 until it goes to zero.

    7631/10 = 763
    763/10 = 76
    76/10 = 7
    7/10 = 0
    What if the number entered is 12? 12/10 = 1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plz answer the following question.....
    By raja2033 in forum C Programming
    Replies: 5
    Last Post: 04-06-2009, 08:35 AM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Newbie Source Code question. Hlp Plz?
    By BOOGIEMAN in forum Game Programming
    Replies: 4
    Last Post: 12-14-2001, 04:30 AM