Code:
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- #include<windows.h>
- #include<mmsystem.h>
- using namespace std;
- int main(void)
- {
- double n1;
- double n2;
- char redo;
- char operation;
- do
- {
- system("CLS"); // If a person enters y it returns the program to this line.
- system("TITLE Calculator"); // Title of Program
- system("Color B4"); // Writing Color
- cout << "Please enter your desired calculation: " << endl;
- cin >> n1 >> operation >> n2;
- switch(operation)
- {
- case '+':
- cout << "Your result is: " << n1 + n2 << endl;
- break;
- case '-':
- cout << "Your result is: " << n1 - n2 << endl;
- break;
- case '*':
- cout << "Your result is: " << n1 * n2 << endl;
- break;
- case 'x':
- cout << "Your result is: " << n1 * n2 << endl;
- break;
- case 'X':
- cout << "Your result is: " << n1 * n2 << endl;
- break;
- case '/':
- if(n2 == 0){
- cout << "That is an invalid operation" << endl;
- }else{
- cout << "Your result is: " << n1 / n2 << endl;
- }
- break;
- default:
- cout << "That is an invalid operation" << endl;
- break;
- }
- cout << "Do you want to calculate something else?(Y/N)" << endl;
- cin >> redo;
- }while(redo == 'y' || redo == 'Y'); // || means or. If a person enters y or Y the program starts again and return to the system CLS line
- system("PAUSE");
- return 0;
- }