Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. //Josh Curl
  2. //11-1-10
  3. //PG1_16_1
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. double memory, n, total;
  12. bool total_set = false, memory_set = false;
  13. char o;
  14. do
  15. {
  16. if(!total_set)
  17. {
  18. cout << "Type in the first number" << endl;
  19. cin >> total;
  20. total_set = true;
  21. }
  22. cout << "Math Operator Options" << endl << "[+]Add [-]Subtract [*]Multiply [/]Divide" << endl << "[s]Square [r]Square Root [p]Power [a]Absolute value" << endl << "[m]Memory options [q]Quit" << endl;
  23. cin >> o;
  24. o = tolower(o);
  25. switch(o)
  26. {
  27. case '+':
  28. cout << "Enter next number: ";
  29. cin >> n;
  30. total += n;
  31. break;
  32. case '-':
  33. cout << "Enter next number: ";
  34. cin >> n;
  35. total -= n;
  36. break;
  37. case '*':
  38. cout << "Enter next number: ";
  39. cin >> n;
  40. total *= n;
  41. break;
  42. case '/':
  43. cout << "Enter next number: ";
  44. cin >> n;
  45. while(n == 0)
  46. {
  47. cout << "Error: Enter a number thats not zero" << endl;
  48. cin >> n;
  49. }
  50. total /= n;
  51. break;
  52. case 's':
  53. total *= total;
  54. break;
  55. case 'r':
  56. total = sqrt(total);
  57. break;
  58. case 'p':
  59. cout << "Enter next number: ";
  60. cin >> n;
  61. total = pow(total, n);
  62. break;
  63. case 'a':
  64. total = abs(total);
  65. break;
  66. case 'c':
  67. total_set = false;
  68. break;
  69. case 'm':
  70. cout << "Memory options:" << endl << "[s]Set [p]Print [c]Clear [+]Add [-]Subtract" << endl;
  71. cin >> o;
  72. switch(o)
  73. {
  74. case 's':
  75. cout << "Enter new value for memory: ";
  76. cin >> n;
  77. memory = n;
  78. memory_set = true;
  79. break;
  80. case 'p':
  81. if(memory_set)
  82. {
  83. cout << memory << endl;
  84. }
  85. else
  86. {
  87. cout << "Error: Memory not set" << endl;
  88. }
  89. break;
  90. case 'c':
  91. memory_set = false;
  92. break;
  93. case '+':
  94. if(memory_set)
  95. {
  96. cout << "Enter next number: ";
  97. cin >> n;
  98. memory += n;
  99. }
  100. else
  101. {
  102. cout << "Error: Memory not set" << endl;
  103. }
  104. break;
  105. case '-':
  106. if(memory_set)
  107. {
  108. cout << "Enter next number: ";
  109. cin >> n;
  110. memory -= n;
  111. }
  112. else
  113. {
  114. cout << "Error: Memory not set" << endl;
  115. }
  116. break;
  117. }
  118. break;
  119.  
  120. }
  121. cout << "Total: ";
  122. if(total_set)
  123. {
  124. cout << total << endl;
  125. }
  126. else
  127. {
  128. cout << "<cleared>" << endl;
  129. }
  130. }
  131. while(o != 'q');
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement