Skip to content

Instantly share code, notes, and snippets.

@SmashedFrenzy16
Created March 28, 2022 15:25
Show Gist options
  • Save SmashedFrenzy16/19878c467b40647624b6700e7abecc5d to your computer and use it in GitHub Desktop.
Save SmashedFrenzy16/19878c467b40647624b6700e7abecc5d to your computer and use it in GitHub Desktop.
A calculator made in C++
#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