Created
February 15, 2022 12:08
-
-
Save CodeMaster7000/9209af3fe9b48c6dcdb839c7329bc793 to your computer and use it in GitHub Desktop.
A simple calculator coded in C++ that performs the 4 basic functions.
This file contains hidden or 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: +, -, *, /: "; | |
cin >> op; | |
cout << "Enter two operands: "; | |
cin >> num1 >> num2; | |
switch(op) { | |
case '+': | |
cout << num1 << " + " << num2 << " = " << num1 + num2; | |
break; | |
case '-': | |
cout << num1 << " - " << num2 << " = " << num1 - num2; | |
break; | |
case '*': | |
cout << num1 << " * " << num2 << " = " << num1 * num2; | |
break; | |
case '/': | |
cout << num1 << " / " << num2 << " = " << num1 / num2; | |
break; | |
default: | |
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