Need a project done?

C++ Programming Developer

Search This Blog

Program to make Calculator in C++. Takes 3 terms as input in expression form.


/*
Calculator in C++. Takes 3 inputs same as we write on our copy (in expression form) using Switch Statement.
*/
#include <iostream>
using namespace std;

void main()
{
double x,y,z; char o,O;
        cout << "How to write: 2-5/2" << endl;
cout << "Write expression consisting of 3 terms: ";
cin>>x>>o>>y>>O>>z;
cout << "Result: ";
switch(o)
{
case '+':
switch(O)
{
case '+':
cout <<x+y+z;
break;
case '-':
cout <<x+y-z;
break;
case '*':
cout <<x+y*z;
break;
case '/':
cout <<x+y/z;
break;
default:
cout << "Error in the last two terms";
}
break;
case '-':
switch(O)
{
case '+':
cout <<x-y+z;
break;
case '-':
cout <<x-y-z;
break;
case '*':
cout <<x-y*z;
break;
case '/':
cout <<x-y/z;
break;
default:
cout << "Error in the last two terms";
}
break;
case '*':
switch(O)
{
case '+':
cout <<x*y+z;
break;
case '-':
cout <<x*y-z;
break;
case '*':
cout <<x*y*z;
break;
case '/':
cout <<x*y/z;
break;
default:
cout << "Error in the last two terms";
}
break;
case '/':
switch(O)
{
case '+':
cout <<x/y+z;
break;
case '-':
cout <<x/y-z;
break;
case '*':
cout <<x/y*z;
break;
case '/':
cout <<x/y/z;
break;
default:
cout << "Error in the last two terms";
}
break;
default:
cout <<"Syntax Error in 1st two terms.";
}
cout << "." << endl;
}
"Don't let anyone ever make you feel like you don't deserve what you want."