c++ 简单的加减乘除计算器

#include
using namespace std;

int main()
{
   double a,b;
   char op;
   cout << "enter a" << endl;
   cin >> a;
   cout << "enter operator" << endl;
   cin >> op;
   cout << "enter b" << endl;
   cin >> b;
   double result;
   if (op=='+')
   {
      result = a + b;
   }
   else if (op=='-')
   {
      result = a-b;
   }
   else if (op=='*')
   {
      result = a*b;
   }
   else if (op=='/'){
      if (b==0){
         cout << "cannot devided by 0\n";
         return 0;

      }
      else{
         result =a/b;
      }
   }
   else
   {
      cout << "invalid operator\n";
      return 0;
   }

   cout << "result is " << result << endl;
   return 0;
}

你可能感兴趣的:(c++ 简单的加减乘除计算器)