Advertisement
J2112O

While Loop Help/Advice "Working Now"

May 8th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. // ex9.c --- converts Fahrenheight to Celcius and Kelvin                                                              
  2.   2 #include <stdio.h>                                                              
  3.   3 #include <stdlib.h>                                                            
  4.   4                                                                                
  5.   5 void Temperatures(double fahr);                                                
  6.   6 int main(void)                                                                  
  7.   7 {                                                                              
  8.   8     double fahr;                                                                
  9.   9                                                                                
  10.  10     printf("Please enter a Fahrenheit temperature: ");                          
  11.  11     scanf("%lf", &fahr);                                                        
  12.  12     Temperatures(fahr);                                                        
  13.  13     while(scanf("%lf", &fahr) >= 1)                                            
  14.  14     {                                                                          
  15.  15         Temperatures(fahr);                                                    
  16.  16     }                                                                          
  17.  17     printf("Done!\n");                                                          
  18.  18     return 0;                                                                  
  19.  19 }                                                                              
  20.  20                                                                                
  21.  21 void Temperatures(double fahr)                                                  
  22.  22 {                                                                              
  23.  23     const double cels = 5.0 / 9.0 * (fahr - 32.0);                              
  24.  24     const double kelv = cels + 273.16;                                          
  25.  25                                                                                
  26.  26     printf("Fahrenheit: %.2lf\n", fahr);                                        
  27.  27     printf("Celsius: %.2lf\n", cels);                                          
  28.  28     printf("Kelvin: %.2lf\n", kelv);                                            
  29.  29 printf("Please enter a Fahrenheit temperature or q to quit. ");            
  30.  30 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement