Advertisement
GarikK

Calculator!

Jan 15th, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. void calculator() {
  9. //variables
  10.  
  11. int num1;
  12. int num2;
  13. int num3;
  14. int num4;
  15. int result1;
  16. int result2;
  17. char operation = ' ';
  18. int max;
  19. while (true)
  20. {
  21. cout << "Choose a number - "; //asking first number
  22. cin >> num1;
  23. cout << "Choose a number two - "; //asking second number
  24. cin >> num2;
  25. result1 = num1 * num2;
  26. cout << "Continue? y/n \n"; // asking for next operation
  27. cin >> operation;
  28. if (operation == 'y')
  29. {
  30. cout << "Choose a number three - \n"; //asking third number
  31. cin >> num3;
  32. cout << "Choose a number four - \n"; //asking fourth number
  33. cin >> num4;
  34. result2 = num3 + num4;
  35. }
  36. else
  37. {
  38. cout << "The first sum is - " << result1; // first result
  39. break;
  40. }
  41. cout << "Do you want to continue with these two results? choose y/n\n";
  42. cin >> operation;
  43. if (operation == 'y')
  44. {
  45. cout << "Choose what I do with them + or - or / or * \n";
  46. char action = ' ';
  47. cin >> action;
  48. switch (action)
  49. {
  50. case '+':
  51. max = result1 + result2;
  52. cout << "The sum of the results - " << max << "\n";
  53. break;
  54. case '-':
  55. max = result1 - result2;
  56. cout << "The differrence of the results - " << max << "\n";
  57. break;
  58. case '*':
  59. max = result1 * result2;
  60. cout << "The product of the results - " << max << "\n";
  61. break;
  62. case '/':
  63. max = result1 / result2;
  64. cout << "The division of the results - " << max << "\n";
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. else
  71. {
  72. cout << "Result one - " << result1 << "\n" << "Result two - " << result2 << "\n";
  73. break;
  74. }
  75. break;
  76. }
  77.  
  78.  
  79. }
  80. int main()
  81. {
  82. calculator();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement