Created
March 28, 2022 15:25
-
-
Save SmashedFrenzy16/19878c467b40647624b6700e7abecc5d to your computer and use it in GitHub Desktop.
A calculator made in C++
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> | |
#include <cmath> | |
using namespace std; | |
int main() | |
{ | |
double num1, num2; | |
char op; | |
cout << "Enter your first number: "; | |
cin >> num1; | |
cout << "Enter your second number: "; | |
cin >> num2; | |
cout << "Enter your operator: "; | |
cin >> op; | |
switch(op) { | |
case '+': | |
cout << num1 + num2 << "\n"; | |
break; | |
case '-': | |
cout << num1 - num2 << "\n"; | |
break; | |
case '*': | |
cout << num1 * num2 << "\n"; | |
break; | |
case '/': | |
cout << num1 / num2 << "\n"; | |
break; | |
default: | |
cout << "Error! Operator not valid!\n"; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment