question about double and float

This is a discussion on question about double and float within the C Programming forums, part of the General Programming Boards category; Hi fellow programmers, I am new to programming and working on learning C. I have am confused about the following. ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    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.

    Code:
    #include <stdio.h>
    main(){
           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);
           fflush(stdin);
           getchar();
           }
    Thanks guys!

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,457
    %lf for double in scanf
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    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

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