Advertisement
tourniquet

Fahrenheit to Celsius Converter

Dec 15th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. /*
  2.  
  3. Fahrenheit to Celsius conversion formula: F = C x 9/5 + 32
  4. Celsius on Fahrenheit conversion formula: C= ([°F] - 32) x 5/9
  5.  
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdbool.h>
  10. #define getch
  11.     #ifdef WIN32
  12.     getch();
  13.     #endif
  14.  
  15. int main () {      
  16.     bool userChoice;
  17.        
  18.     printf ( "To convert Fahrenheit to Celsius, press 0 (zero), to convert Celsius to Fahrenheit, press 1!\n--> " );
  19.     scanf ( "%i", &userChoice );
  20.        
  21.     if ( userChoice == 0 ) {
  22.             FahrToCel ();
  23.         }
  24.            
  25.     else if ( userChoice != 0 ) {
  26.             CelToFahr ();
  27.         }
  28.    
  29.     getch ();
  30.     return 0;
  31.  
  32.     }
  33.        
  34. int CelToFahr ( int celsius ) {
  35.  
  36.     printf ( "Insert temperature in Celsius:\n--> " );
  37.     scanf ( "%i", &celsius );
  38.     printf ( "%3d Celsius =%6.1f Fahrenehit\n", celsius, celsius * 9.0 / 5.0    + 32 );
  39.    
  40.     return 0;
  41.  
  42.     }
  43.    
  44. int FahrToCel ( int fahr ) {
  45.    
  46.     printf ( "Insert temperature Fahreneheit:\n--> " );
  47.     scanf ( "%i", &fahr );
  48.     printf ( "%3d Fahrenheit =%6.1f Celsius\n", fahr, ( fahr - 32 ) * 5.0 / 9.0 );
  49.    
  50.     return 0;
  51.  
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement