Glampkoo

Temperature Converter

Dec 6th, 2013
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. double fiveNinths = 0.5555555555555556;
  6.  
  7. double FtoC(double f)
  8. {
  9.     return (f - 32) * fiveNinths;
  10. }
  11.  
  12. double FtoK(double f)
  13. {
  14.     return (f - 32) * (fiveNinths)+273.15;
  15.    
  16. }
  17.  
  18. double CtoF(double c)
  19. {
  20.     return c * 1.8 + 32;
  21. }
  22.  
  23. double CtoK(double c)
  24. {
  25.     return c + 273.15;
  26. }
  27.  
  28. double KtoF(double k)
  29. {
  30.     return (k - 273.15) * 1.8 + 32;
  31. }
  32.  
  33. double KtoC(double k)
  34. {
  35.     return k - 273.15;
  36. }
  37.  
  38. int main()
  39. {
  40.     double temp;
  41.     short tempSelect;
  42.     string f = "F", c = "C", k = "K";
  43.  
  44.     system("cls");
  45.     cout << "Temperature  Converter" << endl;
  46.     cout << "1. Fahrenheit into Celsius/Kelvin" << endl;
  47.     cout << "2. Celsius into Fahrenheit /Kelvin" << endl;
  48.     cout << "3. Kelvin into Fahrenheit/Celsius" << endl;
  49.     cout << "4. Exit." << endl;
  50.     cin >> tempSelect;
  51.  
  52.     switch (tempSelect)
  53.     {
  54.     case 1:
  55.         system("cls");
  56.         cout << "Fahrenheit into Celsius/Kelvin Converter" << endl;
  57.         cin >> temp;
  58.         system("cls");
  59.         cout << "Fahrenheit into Celsius/Kelvin Converter" << endl;
  60.         cout << temp << "F = " << FtoC(temp) << c << endl;
  61.         cout << temp << "F = " << FtoK(temp) << k << endl;
  62.         system("pause");
  63.         main();
  64.         break;
  65.     case 2:
  66.         system("cls");
  67.         cout << "Celsius into Fahrenheit /Kelvin Converter" << endl;
  68.         cin >> temp;
  69.         system("cls");
  70.         cout << "Celsius into Fahrenheit /Kelvin Converter" << endl;
  71.         cout << temp << "C = " << CtoF(temp) << f << endl;
  72.         cout << temp << "C = " << CtoK(temp) << k << endl;
  73.         system("pause");
  74.         main();
  75.         break;
  76.     case 3:
  77.         system("cls");
  78.         cout << "Kelvin into Fahrenheit/Celsius Converter" << endl;
  79.         cin >> temp;
  80.         system("cls");
  81.         cout << "Kelvin into Fahrenheit/Celsius Converter" << endl;
  82.         cout << temp << "K = " << KtoF(temp) << f << endl;
  83.         cout << temp << "K = " << KtoC(temp) << c << endl;
  84.         system("pause");
  85.         main();
  86.         break;
  87.     case 4:
  88.         system("cls");
  89.         cout << "Goodbye." << endl;
  90.         return 0;
  91.         break;
  92.     default:
  93.         main();
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment