Thread: question about double and float

  1. #1
    Registered User
    Join Date
    Dec 2006

    Post question about double and float

    Hi fellow programmers,
    I am new to programming and working on learning C. I have am confused about the following. I tried to program celsius to fahrenheit converter. If i use float for celsius and fahrenheit, it works. but if i use those two variables as double then it only shows 32 as an answer. Is there something i neeed to know about doubles?? Here is the program.

    #include <stdio.h>
           double celsius;
           double fahrenheit;
           printf("Enter temperature in Celsius: ");
           scanf("%f", &celsius);
           fahrenheit = 32 + celsius * 9.0 / 5.0;
           printf("The temperature in Fahrenheit is %.2f" , fahrenheit);
    Thanks guys!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    %lf for double in scanf
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2006
    It worked! Thanks Bro!

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    The most peaks over 10,000 feet!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - float and double data-type question..
    By ShadeS_07 in forum C Programming
    Replies: 10
    Last Post: 07-14-2008, 06:06 AM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  5. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM