ahmed0saber

Simple Calculator using functions in C++

Nov 5th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void sum(int x , int y)
  4. {
  5.     cout<<"The result = "<<x+y;
  6. }
  7. void sub(int x , int y)
  8. {
  9.     cout<<"The result = "<<x-y;
  10. }
  11. void multi(int x , int y)
  12. {
  13.     cout<<"The result = "<<x*y;
  14. }
  15. void divi(int x , int y)
  16. {
  17.     cout<<"The result = "<<x/y;
  18. }
  19. int main()
  20. {
  21.     int x,y;
  22.     char op;
  23.     cout<<"Enter the first number"<<endl;
  24.     cin>>x;
  25.     cout<<"Enter the second number"<<endl;
  26.     cin>>y;
  27.     cout<<"Enter the operator + - * /"<<endl;
  28.     cin>>op;
  29.     switch(op)
  30.     {
  31.         case '+':
  32.             sum(x,y);
  33.             break;
  34.         case '-':
  35.             sub(x,y);
  36.             break;
  37.         case '*':
  38.             multi(x,y);
  39.             break;
  40.         case '/':
  41.             divi(x,y);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment