Advertisement
tranerius

1. Калькулятор для двух чисел

Dec 11th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     double x_1, y_1, r_1; char symbol;
  5.     cout << "Enter first number" << "\n";
  6.     cin >> x_1;
  7.     cout << "Enter second number" << "\n";
  8.     cin >> y_1;
  9.     cout << "List of operations which you can use are +, -, *, /" << "\n" << "What operation do you want to do?" << "\n";
  10.     cin >> symbol;
  11.     if (symbol == '+') {
  12.         r_1 = x_1 + y_1;
  13.         cout << x_1 << "+" << y_1 << "=" << r_1;
  14.     }
  15.     else if (symbol == '-') {
  16.         r_1 = x_1 - y_1;
  17.         cout << x_1 << "-" << y_1 << "=" << r_1;
  18.     }
  19.     else if (symbol == '*') {
  20.         r_1 = x_1 * y_1;
  21.         cout << x_1 << "*" << y_1 << "=" << r_1;
  22.     }
  23.     else if (symbol == '/') {
  24.         if (y_1 == 0) {cout << "Error";}
  25.         else {
  26.             r_1 = x_1 / y_1;
  27.             cout << x_1 << "/" << y_1 << "=" << r_1 << endl;
  28.         }
  29.     }
  30.     else {
  31.         cout << "You didn't introduce operation" << endl;
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement