fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8. restart:
  9. int a,b,c,x;
  10.  
  11. cout << "Welcome to the advanced arithmetic calculator.\nWhat do you want to do?\n1)Add\n2)Sub\n3)Mul\n4)Div\n\n";
  12. cin >> x;
  13.  
  14. if(x==1||x==2||x==3||x==4)
  15. {
  16. cout << "\nEnter first number.\n\n";
  17. cin >> a;
  18.  
  19. cout << "\nEnter second number.\n\n";
  20. cin >> b;
  21.  
  22. if(x==1)
  23. {
  24. c=a+b;
  25. }
  26.  
  27. else if(x==2)
  28. {
  29. c=a-b;
  30. }
  31.  
  32. else if(x==3)
  33. {
  34. c=a*b;
  35. }
  36. else if(x==4 && b!=0)
  37. {
  38. c=a/b;
  39.  
  40. }
  41. else if(x==4 && b==0)
  42. {
  43. cout << "\nUNDEFINED.\n\n";
  44. goto restart;
  45. }
  46.  
  47. cout <<endl<< c <<" is the answer.\n\n";
  48. }
  49. else
  50. {
  51. cout << "\nERROR\n\n-------------\n\n";
  52. goto restart;
  53. }
  54.  
  55. //-------------------------End of first calc
  56.  
  57. cout <<"What would you like to do next? Would you like to 1)Restart or 2)Exit?\n\n";
  58. cin >> x;
  59.  
  60. if(x==1)
  61. {
  62. goto restart;
  63. }
  64.  
  65. else
  66. {
  67. cout << "\nBye.\n\n";
  68. return 0;
  69. }
  70. }
Success #stdin #stdout 0s 3300KB
stdin
4 2 0 4 2 1 0
stdout
Welcome to the advanced arithmetic calculator.
What do you want to do?
1)Add
2)Sub
3)Mul
4)Div


Enter first number.


Enter second number.


UNDEFINED.

Welcome to the advanced arithmetic calculator.
What do you want to do?
1)Add
2)Sub
3)Mul
4)Div


Enter first number.


Enter second number.


2 is the answer.

What would you like to do next? Would you like to 1)Restart or 2)Exit?


Bye.