Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
Created February 15, 2022 12:08
Show Gist options
  • Save CodeMaster7000/9209af3fe9b48c6dcdb839c7329bc793 to your computer and use it in GitHub Desktop.
Save CodeMaster7000/9209af3fe9b48c6dcdb839c7329bc793 to your computer and use it in GitHub Desktop.
A simple calculator coded in C++ that performs the 4 basic functions.
# 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