Advertisement
Guest User

C++ 10

a guest
Jun 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8. double num;
  9. char degree;
  10. double C2F(double);
  11. double K2F(double);
  12. double N2F(double);
  13.  
  14.  
  15. cout << "This temperature conversion program converts other temperature types to Fahrenheit" << endl;
  16. cout << "The temperature types are : " << endl;
  17. cout << "C - Celcius" << endl;
  18. cout << "K - Kelvin" << endl;
  19. cout << "N - Newton" << endl;
  20. cout << "X - eXit" << endl;
  21.  
  22. cout << "To use the converter, you must input a value and one of the temperature types." << endl;
  23. cout << "For example, 32 C converts 32 degrees from Celsius to Fahrenheit" << endl;
  24.  
  25. cout << "Please enter a value and its type to be converted" << endl;
  26. cin >> num >> degree;
  27.  
  28.  
  29.  
  30.  
  31. while (degree != 'X')
  32. {
  33. cout << "Please enter a value and its type to be converted" << endl;
  34. cin >> num >> degree;
  35.  
  36. switch (degree)
  37. {
  38. case 'C':
  39. cout << num << degree << " is " << C2F(num) << " in Fahrenheit" << endl;
  40. break;
  41.  
  42. case 'K':
  43. cout << num << degree << " is " << K2F(num) << " in Fahrenheit " << endl;
  44. break;
  45.  
  46. case 'N':
  47. cout << num << degree << " is " << N2F(num) << " in Fahrenheit " << endl;
  48. break;
  49.  
  50. default:
  51. cout << "Invalid input" << endl;
  52. break;
  53.  
  54. case 'X':
  55. cout << "eXit" << endl;
  56. exit(0);
  57.  
  58. }
  59. }
  60.  
  61.  
  62.  
  63. return 0;
  64. }
  65.  
  66. double C2F(double num)
  67. {
  68. double convert1 = (num - 273.15) * 1.8000 + 32;
  69. return convert1;
  70. }
  71.  
  72. double K2F(double num)
  73. {
  74. double convert2 = num * 9 / 5 + 32;
  75. return convert2;
  76. }
  77.  
  78. double N2F(double num)
  79. {
  80. double convert3 = num * 60 / 11 + 32;
  81. return convert3;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement