Advertisement
Guest User

Need Help

a guest
Mar 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <iomanip>
  5. #include <math.h>
  6. #include <limits>
  7.  
  8. using namespace std;
  9.  
  10. double f;
  11. double c;
  12. double k;
  13. double result;
  14.  
  15.  
  16. int main()
  17. {
  18.     cout << "Pick a temperature unit K for Kelvin, F for Fahrenheit, C for Celsius: ";
  19.     cin >> result;
  20.     cout << endl;
  21.     if(result == 'f' || result == 'F')
  22.     {
  23.         cout << "This program will tell you what the degrees where you live is in Kelvin and Celsius." << endl;
  24.         cout << endl;
  25.         cout << "What's your temperature in Fahrenheit: ";
  26.        
  27.         while(!(cin >> f)){        
  28.             cin.clear();
  29.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  30.             cout << "Invalid temperature try again. ";
  31.             cout << endl;
  32.             cout << "What's your temperature in Fahrenheit: ";
  33.     }
  34.         cout << endl;
  35.        
  36.         k = c + 273.15;    
  37.         cout << "Your degrees in Kelvin is: " << setprecision(3) << k << " Kelvin" << endl;
  38.         cout << endl;
  39.        
  40.         c = (f - 32) * 5 / 9;          
  41.         cout << "Your degrees in Celsius is: " << setprecision(2) << c << "Celsius" << endl;
  42.         cout << endl;                      
  43.     }
  44.    
  45.     if(result == 'c' || result == 'C')
  46.     {
  47.     cout << "This program will tell you what the degrees where you live is in Kelvin and Fahrenheit." << endl;
  48.     cout << endl;
  49.     cout << "What's your temperature in Celsius: ";
  50.    
  51.     while(!(cin >> c)){        
  52.         cin.clear();
  53.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  54.         cout << "Invalid temperature try again. ";
  55.         cout << endl;
  56.         cout << "What's your temperature in Celsius: ";
  57.     }
  58.         cout << endl;
  59.        
  60.         k = c + 273.15;    
  61.         cout << "Your degrees in Kelvin is: " << setprecision(3) << k << " Kelvin" << endl;
  62.         cout << endl;
  63.        
  64.         (f = (c × 9/5) + 32);    
  65.         cout << "Your degrees in Fahrenheit is: " << setprecision(2) << f << "Fahrenheit" << endl;
  66.         cout << endl;
  67.        
  68.     }
  69.    
  70.     if(result == 'k' || result == 'K')
  71.     {
  72.     cout << "This program will tell you what the degrees where you live is in Fahrenheit and Celsius." << endl;
  73.     cout << endl;
  74.     cout << "What's your temperature in Kelvin: ";
  75.    
  76.     while(!(cin >> k)){        
  77.         cin.clear();
  78.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  79.         cout << "Invalid temperature try again. ";
  80.         cout << endl;
  81.         cout << "What's your temperature in Kelvin: ";
  82.     }
  83.         cout << endl;
  84.        
  85.         f = (k − 273.15) × 9/5 + 32;
  86.         cout << "Your degrees in Fahrenheit is: " << setprecision(2) << f << "Fahrenheit" << endl;
  87.         cout << endl;
  88.        
  89.         c = (f - 32) * 5 / 9;          
  90.         cout << "Your degrees in Celsius is: " << setprecision(2) << c << "Celsius" << endl;
  91.         cout << endl;    
  92.     }  
  93.  
  94.    
  95.    
  96.     if (f <= 65)
  97.     {
  98.         cout << "It must be chilling outside don't forget a coat." << endl;
  99.     }    
  100.     if (f >= 75)
  101.     {        
  102.         cout << "It's pretty warm out no need for a coat." << endl;      
  103.     }
  104.     if (f > 65 && f < 75)
  105.     {
  106.         cout << "It's a little cold but you should need a coat hopefully" << endl;
  107.     }
  108.     return 0;        
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement