Thread: Temperature

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    7

    Thumbs up Temperature

    Code:
    #include <stdio.h>
    
    void main (void)
    
    {
    
    int cel, fah;
    
    
     printf("Temperature Conversion Program\n\n");
    
     printf ("Enter the temperature in Faharenhiet:");
     scanf ("%d", &fah);
     cel = (fah-32.0)*5.0/9.0;
    
     printf ("The Temperature in Celsius is %d\n\n");
    
     }
    Above program is written to convert the temprature in Faharenhiet to Celsius. When I run the program the conversion is not correct. What's wrong with the program? And If I want to show also Faharenhiet value at the end what do I have to write?


    Thank You

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    49
    There was something missing.
    printf ("The Temperature in Celsius is %d\n\n",cel);

    Also it is spelled Fahrenheit.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    printf ("The Temperature in Celsius is %d\n\n");

    You forgot about the format specifier, which will probabaly give you any spurious integer value the copmpiler decides on as the result.

    printf ("The Temperature in Celsius is %d\n\n", cel);
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    Re: Temperature

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	int cel, fah;
    
    	printf("Temperature Conversion Program\n\n");
    	printf("Enter the temperature in Faharenhiet:");
    	scanf("%d", &fah);
     
    	cel = (fah-32.0)*5.0/9.0;
    
    	printf ("The Temperature in Celsius is %d\n\n", cel);
    	return 0;
    }

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You might also want to change the variables from int to float or double since it appears thats what you want.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    You are using the int (integer) data types. It doesn't use decimals, and would just throw them away. Like you wouldn't be able to use 5.9, you would just have 5. And since you are using a fraction to convert it defeats the whole program, so change the int to long or double.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Temperature Conversion code problems
    By eroth88 in forum C Programming
    Replies: 6
    Last Post: 10-22-2006, 01:24 AM
  2. Motherboard Temperature
    By MK4554 in forum Windows Programming
    Replies: 1
    Last Post: 07-18-2006, 10:51 AM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  4. read the CPU temperature
    By BianConiglio in forum Windows Programming
    Replies: 2
    Last Post: 05-19-2004, 11:41 AM
  5. functions ??? help
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2001, 02:33 AM