Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save urmil0071/e871f42e465007f532b862762e288c5a to your computer and use it in GitHub Desktop.
Save urmil0071/e871f42e465007f532b862762e288c5a to your computer and use it in GitHub Desktop.
simple c++ calculator with Switch statements
#include <iostream>
using namespace std;
void main()
{
int a,b;
char c;
cout << "enter the two numbers to calculate" << endl; cin>>a>>b;
cout << " Press the desired operator , + for addition, - for substraction, * for multiplication, / for division " << endl; cin>>c;
switch (c)
{
case '+' :
{cout << "the addition result between the two are == " << a+b << endl;};break;
case '-' :
{cout << "the subtraction result between the two are == " << a-b << endl;};break;
case '*' :
{cout << "the multiplication result between the two are == " << a*b << endl;};break;
case '/' :
{cout << "the division result between the two are == " << a/b << endl;};break;
default : cout << "invalid input, thats not a mathematical operator" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment