fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void calculator()
  4. {
  5. cout<<"Enter 2 numbers and the operator between it\n";
  6. double a,b;char op;
  7. cin>>a>>op>>b;
  8. if(op=='+')
  9. {
  10. cout<<"result \t "<<a+b;
  11. }
  12. else if(op=='-')
  13. {
  14. cout<<"result \t "<<a-b;
  15. }
  16. else if(op=='*')
  17. {
  18. cout<<"result \t "<<a*b;
  19. }
  20. else if(op=='/')
  21. {
  22. if(b==0)
  23. {
  24. cout<<"run time error\n";
  25. }
  26. else
  27. {
  28. cout<<"result \t "<<a/b;
  29. }
  30. }
  31. }
  32. void square()
  33. {
  34. cout<<"Enter square side \n";
  35. long long side;cin>>side;
  36. cout<<side*side;
  37. }
  38. void rectangle()
  39. {
  40. cout<<"Enter height,width\n";
  41. long long height,width;cin>>height>>width;
  42. cout<<height*width;
  43. }
  44. void triangle()
  45. {
  46. long long height,base;float ans;
  47. cout<<"Enter height and base :\n";
  48. cin>>height>>base;
  49. ans=0.5*height*base;
  50. cout<<"Area of triangle is : "<<ans;
  51. }
  52. int main()
  53. {
  54. cout<<"Welcome \n";
  55. cout<<"For the calculator press 1: \n";
  56. cout<<"For area of the rectangle press 2: \n";
  57. cout<<"For the square area press 3: \n";
  58. cout<<"For area of the triangle press 4: \n";
  59. int operation;cin>>operation;
  60. system("cls");
  61. if(operation==1)
  62. {
  63. calculator();
  64. }
  65. else if(operation==2)
  66. {
  67. rectangle();
  68. }
  69. else if(operation==3)
  70. {
  71. square();
  72. }
  73. else
  74. {
  75. triangle();
  76. }
  77. cout<<"\nThanks Very Much";
  78. return 0;
  79. }
Success #stdin #stdout #stderr 0.01s 5280KB
stdin
Standard input is empty
stdout
Welcome 
For the calculator press 1: 
For area of the rectangle press 2: 
For the square area press 3: 
For area of the triangle press 4: 
Enter height and base :
Area of triangle is : 0
Thanks Very Much
stderr
sh: 1: cls: not found