fork(1) download
  1. #include<iostream>
  2. using namespace std;
  3. void fun(char op, float a, float b);
  4. int main()
  5. {
  6. float a, b, sum, sub, mul, divide, mod;
  7. char op;
  8.  
  9. //operands and operators are enterd by the user
  10. cout<<"Enter any two operands with operator=";
  11. cin>>a>>op>>b;
  12. fun(op, a, b);
  13. return 0;
  14. }
  15. void fun(char op, float a, float b)
  16. {
  17. if(op=='+')
  18. {
  19. float sum=a+b;
  20. cout<<"\nAddition of two numbers is="<<sum;
  21. }
  22. else if(op=='-')
  23. {
  24. float sub=a-b;
  25. cout<<"\nSubtraction of two numbers is="<<sub;
  26. }
  27. else if(op=='*')
  28. {
  29. float mul=a*b;
  30. cout<<"\nMultiplication of two numbers is="<<mul;
  31. }
  32. else if(op=='/')
  33. {
  34. float divide=a/b;
  35. cout<<"\nDivision of two number is="<<divide;
  36. }
  37. else
  38. {
  39. cout<<"\nInvalid operator.......";
  40. }
  41. }
Success #stdin #stdout 0s 15232KB
stdin
10+2
stdout
Enter any two operands with operator=
Addition of two numbers is=12