fork download
  1. #include <iostream>
  2. using namespace std;
  3. float add( float x, float y){
  4. return x+y;
  5. }
  6. float sub( float x, float y){
  7. cout<<"do you want +ve results? (1-->True, 0--> False) "<<endl;
  8. bool A; cin>>A;
  9. if(A){
  10. if( x > y){
  11. return x-y;
  12. }else{
  13. return y-x;
  14. }
  15. }
  16. return x-y;
  17. }
  18.  
  19. float mul( float x, float y) {
  20. return x*y;
  21. }
  22.  
  23. float div(float x, float y) {
  24. cout<<"do you want to divide the bigger over the smaller? (1-->True, 0--> False) "<<endl;
  25. bool A; cin>>A;
  26. if(A){
  27. if( x > y){
  28. return x/y;
  29. }else{
  30. return y/x;
  31. }
  32. } else{}
  33. return x/y;
  34. }
  35. int main() {
  36. float num1, num2;
  37. cout<<"enter the first number: \n";
  38. cin>>num1;
  39. cout<<"enter the second number: \n";
  40. cin>>num2;
  41. int x;
  42. cout<<"which calculation you want to make?\n";
  43. cout<<"1-->Addition\n"<<"2-->Subtraction\n" <<"3-->Multiplication\n"<<"4-->Division\n";
  44. cin>>x;
  45. switch (x) {
  46. case 1:
  47. cout << add(num1, num2);
  48. break;
  49. case 2:
  50. cout << sub(num1, num2);
  51. break;
  52. case 3:
  53. cout<< mul(num1, num2);
  54. break;
  55. case 4:
  56. cout<< div(num1, num2);
  57. break;
  58. default:
  59. cout << " Invalid input";
  60. }
  61. }
  62.  
Success #stdin #stdout 0s 5324KB
stdin
2
3
1
stdout
enter the first number: 
enter the second number: 
which calculation you want to make?
1-->Addition
2-->Subtraction
3-->Multiplication
4-->Division
5