An advanced calculator with switch case
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
start:
int a = 0;
double value1;
double value2;
double result;
char oOperator;
cout << "Enter a number then a operator and then another number! e.g \n1+1, 1x1, 1/1, 1-1 (x + / -) \a \n";
cin >> value1;
cin >> oOperator;
cin >> value2;
switch (oOperator)
{
case 'x':
case 'X':
case '*':
{
result = value1 * value2;
cout << result;
break;
}
case '+':
{
result = value1 + value2;
cout << result;
break;
}
case '-':
{
result = value1 - value2;
cout << result;
break;
}
case '/':
{
result = value1 / value2;
cout << result;
break;
}
default:
{
cout << "!!!Was that a mathmatical symbol?!!!";
break;
}
}
cout << "\n";
cout << "try again press 1 or quit 2...and enter";
cin >> a;
if (a==1)
goto start;
if (a==2)
{
cout << "thank you\n";
system("PAUSE");
}
return 0;
}
#include <cstdlib>
using namespace std;
int main()
{
start:
int a = 0;
double value1;
double value2;
double result;
char oOperator;
cout << "Enter a number then a operator and then another number! e.g \n1+1, 1x1, 1/1, 1-1 (x + / -) \a \n";
cin >> value1;
cin >> oOperator;
cin >> value2;
switch (oOperator)
{
case 'x':
case 'X':
case '*':
{
result = value1 * value2;
cout << result;
break;
}
case '+':
{
result = value1 + value2;
cout << result;
break;
}
case '-':
{
result = value1 - value2;
cout << result;
break;
}
case '/':
{
result = value1 / value2;
cout << result;
break;
}
default:
{
cout << "!!!Was that a mathmatical symbol?!!!";
break;
}
}
cout << "\n";
cout << "try again press 1 or quit 2...and enter";
cin >> a;
if (a==1)
goto start;
if (a==2)
{
cout << "thank you\n";
system("PAUSE");
}
return 0;
}
1. copy this code or download source file .
2. open dev c++ and make a new source file . paste the code
3. compile and run.
2. If you get an idea about it develup the code. just like i do.
2. open dev c++ and make a new source file . paste the code
3. compile and run.
2. If you get an idea about it develup the code. just like i do.
If you have a basic knowledge in c++ you can understand this code......or else download tutorial on home page and study the syntax of switch case...
Download Source file .click download...
advanced_calculator.cpp | |
File Size: | 1 kb |
File Type: | cpp |
If you dont understand any thing in tutorial just post your doubts.....