Thread: Simple output/input program not working?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    158

    Simple output/input program not working?

    Basically the program intakes two numbers and subtracts them. The reimbursement($) would then be multiplied by .35

    (Standard stuff)

    double OD1
    double OD2



    printf("Enter beginning odometer reading")



    scanf("%lf", &OD1)

    printf("Enter ending odometer reading")

    scanf("%lf", &OD2)

    double diff= OD2-OD1;
    double reimbursement= rate*diff

    print("You traveled %lf amount of miles At $.35 per mile, your reimbursement is %lf",diff,reimbursement)

    The program works if i enter whole numbers/integers. But as soon as i put in a decimal it crashes and it doesn't work.

    Why is that? I have doubles declared. I have %lf in the scanf function..

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    5
    I don't see where you declared "rate". Can you post your actual code?

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    41
    Can you post your code here?

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Don't type your program into the post and don't pick and choose which parts to show.

    Instead, copy and paste all of your actual code and remember to put it in code tags.

    Also, for the printf (not print!), you should just use %f, not %lf (although you DO have to use %lf in the scanf to read a double, as you're doing).
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having an output issue working with input file, golf game.
    By douglas481 in forum C Programming
    Replies: 10
    Last Post: 03-29-2012, 05:43 PM
  2. Replies: 3
    Last Post: 04-27-2011, 09:46 PM
  3. Replies: 5
    Last Post: 04-25-2011, 01:12 PM
  4. Program stops working as soon as I input value?..
    By darkmagic in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2011, 02:18 AM
  5. File Input and Output, simple.
    By Vber in forum C Programming
    Replies: 5
    Last Post: 11-17-2002, 02:57 PM