Advertisement
Guest User

Untitled

a guest
Aug 16th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main () {
  8.  
  9.     int n1,n2;
  10.     char operato;
  11.  
  12.     cin >> n1 >> n2 >> operato;
  13.  
  14.  
  15.     if (operato=='+'){
  16.         int result=n1+n2;
  17.         if(result%2==0){
  18.         cout << n1 <<" + "<<n2<<" = "<<result<<" - even"<<endl;
  19.         }else if (result%2==1){
  20.         cout << n1 <<" + "<<n2<<" = "<<result<<" - odd"<<endl;
  21.         }
  22.     }else if(operato=='-'){
  23.         int result=n1-n2;
  24.         if(result%2==0){
  25.         cout << n1 <<" - "<<n2<<" = "<<result<<" - even"<<endl;
  26.         }else if (result%2==1){
  27.         cout << n1 <<" - "<<n2<<" = "<<result<<" - odd"<<endl;
  28.         }
  29.     }else if(operato=='*'){
  30.         int result=n1*n2;
  31.         if(result%2==0){
  32.         cout << n1 <<" * "<<n2<<" = "<<result<<" - even"<<endl;
  33.         }else if (result%2==1){
  34.         cout << n1 <<" * "<<n2<<" = "<<result<<" - odd"<<endl;
  35.         }
  36.     }
  37.  
  38.  
  39.      else if(operato=='/' ){
  40.        if (n2!=0){
  41.        double dResult=(n1*1.00)/n2;
  42.         cout.setf(ios::fixed);
  43.             cout.precision(2);
  44.             cout << n1 <<" / "<<n2<<" = "<<dResult<<endl;
  45.        }else if (n2==0)
  46.         cout << "Cannot divide "<<n1<<" by zero" << endl;
  47.     }else if(operato=='%'){
  48.         if (n2!=0){
  49.        int result=n1%n2;
  50.          cout << n1 <<" % "<<n2<<" = "<<result<<endl;
  51.        }else if (n2==0)
  52.         cout << "Cannot divide "<<n1<<" by zero" << endl;
  53.     }
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement