develop a c++ program to implement simple calculator code example

Example: how to build a calculator using c++

#include <iostream>

using namespace std;

int main()
{
int num1;
int num2;
char op;
  
  cout << "Enter a number:" << endl;
  cin >> num1; //takes input
  
  cout << "Enter another number:" << endl; //prints some prompt
  cin >> num2;
  
  cout << "Enter a operator:" << endl; //prints some prompt
  cin >> op;
  
  if(op == '+')
  {
  cout << "Result = " << num1 + num2 << endl;
  }else if(op == '-'){
  cout << "Result = " << num1 - num2 << endl;
  }else if(op == '*'){
  cout << "Result = " << num1 * num2 << endl;
  }else if(op == '/'){
  cout << "Result = " << num1 / num2 << endl;
  }
  
  
}

Tags:

Cpp Example