Skip to content

Instantly share code, notes, and snippets.

@aligalehban
Created June 21, 2018 04:27
Show Gist options
  • Save aligalehban/74dff0b6c57cf98a7844529137c93f1b to your computer and use it in GitHub Desktop.
Save aligalehban/74dff0b6c57cf98a7844529137c93f1b to your computer and use it in GitHub Desktop.
Calculator in c++ source code -www.alighalehban.com
# include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2;
cout << "Enter operator either + or - or * or /: ";
cin >> op;
cout << "Enter two operands: ";
cin >> num1 >> num2;
switch(op)
{
case '+':
cout << num1+num2;
break;
case '-':
cout << num1-num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1/num2;
break;
default:
// If the operator is other than +, -, * or /, error message is shown
cout << "Error! operator is not correct";
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment