SHARE
TWEET

Untitled

a guest Jun 11th, 2017 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int main(int argc, const char * argv[]) {
  4.     float num_1, num_2, result;
  5.     char b;
  6.     while (true) {
  7.         cin >> num_1;
  8.         cin >> b;
  9.         cin >> num_2;
  10.         if (((num_1 <= 0 || num_1 >= 0) && (num_2 <= 0 || num_2 >= 0) && (b == '+' || b == '*' || b == '%' || b == '-' || b == '/'))) {
  11.         }
  12.         else {
  13.             cout << "You specified an incorrect action!" << endl;
  14.         }
  15.         if (b == '/' && num_2 == 0) {
  16.             cout << "Error, can not divide by zero!" << endl;
  17.    
  18.         }
  19.         else if(b == '%' && num_2 == 0) {
  20.             cout << "Error, can not divide by zero!" << endl;
  21.         }
  22.         else {
  23.             if (b == '/') {
  24.                 result = num_1 / num_2;
  25.                 cout << num_1 << "/" << num_2 << "=" << result << endl;
  26.                 return 0;
  27.                 }
  28.             if (b == '+') {
  29.                 result = num_1 + num_2;
  30.                 cout << num_1 << "+" << num_2 << "=" << result << endl;
  31.                 return 0;
  32.             }
  33.             if (b == '*') {
  34.                 result = num_1 * num_2;
  35.                 cout << num_1 << "*" << num_2 << "=" << result << endl;
  36.                 return 0;
  37.             }
  38.             if (b == '-') {
  39.                 result = num_1 - num_2;
  40.                 cout << num_1 << "-" << num_2 << "=" << result << endl;
  41.                 return 0;
  42.             }
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top