Created
June 21, 2018 04:27
-
-
Save aligalehban/74dff0b6c57cf98a7844529137c93f1b to your computer and use it in GitHub Desktop.
Calculator in c++ source code -www.alighalehban.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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