Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. int choice = 0;
  12. float num1;
  13. float num2;
  14. int operation = 0;
  15. string more;
  16. string blank;
  17. bool mainExit = false;
  18.  
  19. while (!mainExit)
  20. {
  21. cout << "Would you like to do a calculation or a conversion?? " << endl;
  22. cout << "Press '1' for a four function calculator " << endl;
  23. cout << "Press '2' to calculator a convertion between: " << endl;
  24. cout << "Celcius, Fahrenheit, and Kelvin. " << endl;
  25.  
  26. cin >> choice;
  27.  
  28. if (choice == 1)
  29. {
  30. cout << "--------------------" << endl;
  31. cout << "1. Addition" << endl;
  32. cout << "2. Subtraction" << endl;
  33. cout << "3. Power" << endl;
  34. cout << "4. Multiplication" << endl;
  35. cout << "5. Division" << endl;
  36. cout << "6. Exit" << endl;
  37. cout << "--------------------" << endl;
  38. cout << "Enter your choice: ";
  39. cin >> operation;
  40. cout << "Enter two numbers seperated by a 'space' ";
  41. cin >> num1 >> num2;
  42.  
  43. bool exit = false;
  44. while (!exit)
  45. {
  46. if (operation == 1)
  47. {
  48. cout << num1 << " + " << num2 << " = " << (num1 + num2) << endl;
  49. exit = true;
  50. }
  51. else if (operation == 2)
  52. {
  53. cout << num1 << " - " << num2 << " = " << (num1 - num2) << endl;
  54. exit = true;
  55. }
  56. else if (operation == 3)
  57. {
  58. cout << num1 << "^" << num2 << " = " << pow(num1, num2) << endl;
  59. exit = true;
  60. }
  61. else if (operation == 4)
  62. {
  63. cout << num1 << " * " << num2 << " = " << (num1 * num2) << endl;
  64. exit = true;
  65. }
  66. else if (operation == 5)
  67. {
  68. cout << num1 << " / " << num2 << " = " << (num1 / num2) << endl;
  69. exit = true;
  70. }
  71. else if (operation == 6)
  72. {
  73. cout << "Bye!" << endl;
  74. exit = true;
  75. }
  76. else
  77. {
  78. cout << "You entered an invalid choice!";
  79.  
  80. cout << "--------------------" << endl;
  81. cout << "1. Addition" << endl;
  82. cout << "2. Subtraction" << endl;
  83. cout << "3. Power" << endl;
  84. cout << "4. Multiplication" << endl;
  85. cout << "5. Division" << endl;
  86. cout << "6. Exit" << endl;
  87. cout << "--------------------" << endl;
  88. cout << "Enter your choice: ";
  89. cin >> operation;
  90. cout << "Enter two numbers seperated by a 'space' ";
  91. cin >> num1 >> num2;
  92. }
  93. }
  94.  
  95. cout << "Type anything and press 'Enter' to exit" << endl;
  96. cin >> blank;
  97. mainExit = true;
  98.  
  99. }
  100.  
  101.  
  102.  
  103.  
  104. if (choice == 2)
  105. {
  106. bool exit = false;
  107. float temp;
  108. float tempEnd;
  109. while (!exit)
  110. {
  111. cout << "1. Farenheit to Celsius" << endl;
  112. cout << "2. Celsius to Farenheit" << endl;
  113. cout << "3. Farenheit to Kelvin" << endl;
  114. cout << "Enter your choice: ";
  115. cin >> operation;
  116.  
  117. if (operation == 1)
  118. {
  119. cout << "Enter your temperature in Farenheit" << endl;
  120. cin >> temp;
  121.  
  122. tempEnd = ((temp - 32.0) * (5.0 / 9.0));
  123.  
  124. cout << temp << "F = " << tempEnd << "C" << endl;
  125.  
  126. exit = true;
  127. }
  128. else if (operation == 2)
  129. {
  130. cout << "Enter your temperature in Celcius" << endl;
  131. cin >> temp;
  132.  
  133. tempEnd = ((temp * (9.0 / 5.0)) + 32.0);
  134.  
  135. cout << temp << "C = " << tempEnd << "F" << endl;
  136.  
  137. exit = true;
  138. }
  139. else if (operation == 3)
  140. {
  141. cout << "Enter your temperature in Farenheit" << endl;
  142. cin >> temp;
  143.  
  144. tempEnd = ((temp + 459.67) * (5.0 / 9.0));
  145.  
  146. cout << temp << "F = " << tempEnd << "K" << endl;
  147.  
  148. exit = true;
  149. }
  150. else
  151. {
  152. cout << "You Entered an ivalid choice" << endl;
  153. }
  154. }
  155. cout << "Type anything and press 'Enter' to exit" << endl;
  156. cin >> blank;
  157. mainExit = true;
  158. }
  159.  
  160. else
  161. {
  162. cout << "You Entered an ivalid choice" << endl;
  163. }
  164.  
  165. }
  166. return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement