Guest User

Untitled

a guest
Apr 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. start:
  9. int a, b, c;
  10. int op, select(0);
  11. while (select != -1)
  12. {
  13. cout<<"----------------------\n";
  14. cout<<"Number"<<setw(14)<<"Operation";
  15. cout<<"\n----------------------\n";
  16. cout<<"1"<<setw(20)<<"Addition\n"<<"2"<<setw(20)<<"Subtraction\n"<<"3"<<setw(20)<<"Multiplication\n"<<"4"<<setw(20)<<"Division\n"<<"5"<<setw(20)<<"Modulus\n"<<"6"<<setw(20)<<"Difference\n"<<"7"<<setw(20)<<"Exit Program\n";
  17. cout<<"Enter operation number: ";
  18. cin>>op;
  19.  
  20. while ((op>7) || (op<1))
  21. {
  22. cout<<"Operation must be a number from 1 - 7\n";
  23. cout<<"Enter operation number: ";
  24. cin>>op;
  25. }
  26.  
  27.  
  28. if (op == 7)
  29. return 0;
  30.  
  31. cout<<"Enter the first number: ";
  32. cin>>a;
  33. cout<<"\nEnter the second number: ";
  34. cin>>b;
  35. switch(op)
  36. {
  37. case 1: c = a+b;
  38. break;
  39. case 2: while ((select<1)||(select>2))
  40. {
  41. cout<<"Press 1 for "<<a<< " - "<<b<<endl<<"Press 2 for "<<b<<" - "<<a<<endl;
  42. cin>>select;
  43. switch(select)
  44. {
  45. case 1: c = a-b;
  46. break;
  47. case 2: c = b-a;
  48. break;
  49. default: cout<<"Number must be 1 or 2\n";
  50. }
  51. }
  52. break;
  53. case 3: c = a*b;
  54. break;
  55. case 4: while ((select<1)||(select>2))
  56. {
  57. cout<<"Press 1 for "<<a<< " / "<<b<<endl<<"Press 2 for "<<b<<" / "<<a<<endl;
  58. cin>>select;
  59. switch(select)
  60. {
  61. case 1: c = a/b;
  62. break;
  63. case 2: c = b/a;
  64. break;
  65. default: cout<<"Number must be 1 or 2\n";
  66. }
  67. }
  68. break;
  69. case 5: while ((select<1)||(select>2))
  70. {
  71. cout<<"Press 1 for "<<a<< " % "<<b<<endl<<"Press 2 for "<<b<<" % "<<a<<endl;
  72. cin>>select;
  73. switch(select)
  74. {
  75. case 1: c = a%b;
  76. break;
  77. case 2: c = b%a;
  78. break;
  79. default: cout<<"Number must be 1 or 2\n";
  80. }
  81. }
  82. break;
  83. case 6: c = abs(a-b);
  84. break;
  85. case 7: return 0;
  86. default: cout<<"Must be a number from 1 to 7";
  87. }
  88. cout<<"The answer is: "<<c<<endl;
  89. }
  90. system("pause");
  91. }
Add Comment
Please, Sign In to add comment