Monday, 6 February 2017

Basic Calculator in C++


#include<iostream>
using namespace std;
void
main()
{
 int number1;
 int number2;
 char operation;
 while (true) {
  cout << "Enter the first number : " << endl;
  cin >> number1;
  cout << "Enter the operation : " << endl;
  cin >> operation;
  cout << "Enter the second number: " << endl;
  cin >> number2;

  switch (operation) {
  case '+':
   cout << number1 + number2 << endl;
   break;
  case '-':
   cout << number1 - number2 << endl;
   break;
  case '*':
   cout << number1*number2 << endl;
   break;
  case '/':
   cout << number1 / number2 << endl;
   break;
  }
 }

 system("pause");
}

No comments:

Post a Comment