Advertisement
notjacob

basic calculator

Nov 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <iostream>
  2. int
  3. main ()
  4. {
  5. int n1 = 0;
  6. int n2 = 0;
  7. int solved = 0;
  8. int type = 0;
  9. bool issolved = false;
  10.  
  11. while (issolved = true) {
  12. std::cout << "What type of math would you like to do?\n\n" << "1) Addition\n2) Subtraction\n3) Multiplication\n4) Division\n";
  13. std::cin >> type;
  14.  
  15. if (type == 1) {
  16. std::cout << "For: addition\n\n";
  17. std::cout << "Enter your first number\n";
  18. std::cin >> n1;
  19. std::cout << "Enter your second number\n";
  20. std::cin >> n2;
  21. solved = n1 + n2;
  22. std::cout << "The solution is " << solved << "\n";
  23. issolved = true;
  24.  
  25. }
  26. else if (type == 2) {
  27. std::cout << "For: subtraction\n\n";
  28. std::cout << "Enter your first number\n";
  29. std::cin >> n1;
  30. std::cout << "Enter your second number\n";
  31. std::cin >> n2;
  32. solved = n1 - n2;
  33. std::cout << "The solution is " << solved << "\n";
  34. issolved = true;
  35. }
  36. else if (type == 3) {
  37. std::cout << "For: multiplication\n\n";
  38. std::cout << "Enter your first number\n";
  39. std::cin >> n1;
  40. std::cout << "Enter your second number\n";
  41. std::cin >> n2;
  42. solved = n1 * n2;
  43. std::cout << "The solution is " << solved << "\n";
  44. issolved = true;
  45. }
  46. else if (type == 4) {
  47. std::cout << "For: division\n\n";
  48. std::cout << "Enter your first number\n";
  49. std::cin >> n1;
  50. std::cout << "Enter your second number\n";
  51. std::cin >> n2;
  52. solved = n1 / n2;
  53. std::cout << "The solution is " << solved << "\n";
  54. issolved = true;
  55. }
  56. else {
  57. std::cout << "Invalid type\n";
  58. issolved = true;
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement