SHARE
TWEET

Untitled

a guest Jun 11th, 2017 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.     int calc(float *num_1, float *num_2, char *b) {
  5.             float result;
  6.             if (*b == '/') {
  7.                 result = *num_1 / *num_2;
  8.                 cout << *num_1 << "/" << *num_2 << "=" << result << endl;
  9.                 return 0;
  10.             }
  11.             if (*b == '+') {
  12.                 result = *num_1 + *num_2;
  13.                 cout << *num_1 << "+" << *num_2 << "=" << result << endl;
  14.                 return 0;
  15.             }  
  16.             if (*b == '*') {
  17.                 result = *num_1 * *num_2;
  18.                 cout << *num_1 << "*" << *num_2 << "=" << result << endl;
  19.                 return 0;
  20.             }
  21.             if (*b == '-') {
  22.                 result = *num_1 - *num_2;
  23.                 cout << *num_1 << "-" << *num_2 << "=" << result << endl;
  24.                 return 0;
  25.             }
  26.         }
  27. int main(int argc, const char * argv[]) {
  28.     float num_1;
  29.     float num_2;
  30.     char b;
  31.         cin >> num_1;
  32.         cin >> b;
  33.         cin >> num_2;
  34.         /if (((num_1 <= 0 || num_1 >= 0) && (num_2 <= 0 || num_2 >= 0) && (b == '+' || b == '*' || b == '%' || b == '-' || b == '/'))) {
  35.         }
  36.         else {
  37.             cout << "You specified an incorrect action!" << endl;
  38.         }
  39.         if (b == '/' && num_2 == 0) {
  40.             cout << "Error, can not divide by zero!" << endl;
  41.         }
  42.         else {
  43.             calc(num_1, num_2, b);
  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