Thread: double to float

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    63

    double to float

    I wrote a program converting fahrenheit to celsius but the requirement calls for using int for fahrenheit and float for celsius. Obviously thats leading to possible loss of data warnings. What can I do? And does anyone know why the "0" isn't showng in the celsius column? I think it was there but I changes something and now its gone?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int main()
    
    {
    
    int fahrenheit;
    float celsius;
    int lower, upper, step;
    
    printf( "Fahrenheit     Celsius\n\n" );
    
    lower = 0;
    upper = 212;
    step = 1;
    
    fahrenheit = lower;
    
    
    
    while (fahrenheit <= upper)
    	{
    		celsius = ( 5.0/9.0 ) * ( fahrenheit - 32.0 );
    		printf( "%10.0d  %+10.3f\n", fahrenheit, celsius );
    		fahrenheit = fahrenheit + step;
    	}
    	return 0;
    }
    Last edited by jsbeckton; 11-07-2005 at 04:22 PM.

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Do these changes
    Code:
    #include <stdlib.h>
    
    
    int main()
    
    {
    
    int fahrenheit;
    float celsius;
    int lower, upper, step;
    
    printf( "Fahrenheit     Celsius\n\n" );
    
    lower = 0;
    upper = 212;
    step = 1;
    
    fahrenheit = lower;
    
    
    
    while (fahrenheit <= upper)
    	{
    		celsius = ( 5.0f/9.0f ) * ( fahrenheit - 32.0f );
    		printf( "%10.0d  %+10.3f\n", fahrenheit, celsius );
    		fahrenheit = fahrenheit + step;
    	}
    	return 0;
    }

  3. #3
    Dyadic Alexthunder's Avatar
    Join Date
    Sep 2005
    Location
    Philippines
    Posts
    16
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
    
       int fahrenheit;
       float celsius;
       int lower, upper, step;
    
       printf( "Fahrenheit     Celsius\n\n" );
    
       lower = 0;
       upper = 212;
       step = 1;
    
       fahrenheit = lower;
    
       while (fahrenheit <= upper)
          {
    	celsius = ( 5.0f/9.0f ) * ( fahrenheit - 32.0f );
    	printf( "%10.0d  %+10.3f\n", fahrenheit, celsius );
    	fahrenheit = fahrenheit + step;
          }
       return 0;
    }
    ahihih
    Last edited by Alexthunder; 11-07-2005 at 11:50 PM.
    An apprentice carpenter may want only a hammer and saw, but a master craftsman employs many precision tools. Computer programming likewise requires sophisticated tools to cope with the complexity of real applications, and only practice with these tools will build skill in their use. Robert L. Kruse

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  2. Need help with program
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 06-10-2007, 08:05 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Im stuck....
    By dAzed in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 04:50 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM