Thread: ı need help

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    6

    ı need help

    Write a program that only uses getchar() for input, and can input a double number. You can use printf() to print the integer and confirm it was read in correctly. Assume the number is positive.


    ı just started c.I have no idea how to solve this problem.Is there any help with this question?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,232
    It sounds like your instructions are contradictory: you are told "can input a double number" and also "print the integer and confirm it was read in correctly". So, is the input in the format of a double or an integer? Check with your instructor.

    If your instructor says double, then also check what exactly is the format as double allows for scientific notation. I would guess it would only be a simple sequence of digits, decimal point, then more digits.
    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
    Mar 2019
    Posts
    6
    could you write as a code?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,525
    Yes, start by writing a getchar() loop which prints a message depending on whether the input character is '0' to '9' (good) or anything else (bad).

    > could you write as a code?
    Not until you post some effort of your own.

    We're guides for your journey to be a programmer, not mules to carry you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2017
    Posts
    692
    Quote Originally Posted by GhooSe View Post
    could you write as a code?
    No problem!

    OGVCJ FEZCJ JIRCP DJFVM COLBB RESGQ PTJJX SFBQJ
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    If you want to cheat on your homework assignment, why don't you just google "c language getchar()"?

    Involving us just seems like not learning with more steps.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Tags for this Thread