//Keeley's Project 3 - Ocotober 11th 2009
//Calculator Revision - 1
#include <iostream>
#include <conio.h>
usingnamespace std;
int main()
{
int Operator;
double IntegerA1;
double IntegerA2;
double IntegerS1;
double IntegerS2;
double IntegerM1;
double IntegerM2;
double IntegerD1;
double IntegerD2;
cout << "Keeley's Calculator\n";
cout << "Please choose what operation you want to do and press enter\n\n";
cout << "1 = Addition 2 = Subtraction 3 = Multiplication 4 = Division\n\n";
cin >> Operator;
if(Operator = 1) cout << "\nYou choose Addition\n";
cout << "Please type the number you want to add\n\n";
cin >> IntegerA1;
cout << "\nYou typed in " << IntegerA1 << ", please type in the number you want to add to " << IntegerA1 <<"\n\n";
cin >> IntegerA2;
cout << "\n\nYou typed in " << IntegerA2 << " and the answer is " << IntegerA1 + IntegerA2;
cout <<_getch();
if(Operator = 2) cout << "\n\nYou choose Subtraction\n";
cout << "Please type the number you want to subtract\n\n";
cin >> IntegerS1;
cout << "You typed in " << IntegerS1 << ", please type in the number you want to subtract from " << IntegerS1 <<"\n\n";
cin >> IntegerS2;
cout << "\n\nYou typed in " << IntegerS2 << " and the answer is " << IntegerS1 - IntegerS2;
cout <<_getch();
if(Operator = 3) cout << "\n\nYou choose Multiplication\n";
cout << "Please type the number you want to multiply\n\n";
cin >> IntegerM1;
cout << "You typed in " << IntegerM1 << ", please type in the number you want to multiply to " << IntegerM1 <<"\n\n";
cin >> IntegerM2;
cout << "\n\nYou typed in " << IntegerM2 << " and the answer is " << IntegerM1 * IntegerM2;
cout <<_getch();
if(Operator = 4) cout << "\n\nYou choose Division\n";
cout << "Please type the number you want to divide\n\n";
cin >> IntegerD1;
cout << "You typed in " << IntegerD1 << ", please type in the number you want to divide to " << IntegerD1 <<"\n\n";
cin >> IntegerD2;
cout << "\n\nYou typed in " << IntegerD2 << " and the answer is " << IntegerD1 / IntegerD2;
cout <<_getch();
return 0;
}
When I press 1,2,3,4, it will always go to Addition why?
@helios Oh wow, I can't believe I used = and forgot the braces, thanks!
@thatGuy I never learnt how to do that yet, I'm following some tutorial and it never told me how to pause a program so I can't learn from the examples and a quick google gave me _getch(); :p
if(Operator == 1){ cout << "\nYou choose Addition\n";
cout << "Please type the number you want to add\n\n";
cin >> IntegerA1;
cout << "\nYou typed in " << IntegerA1 << ", please type in the number you want to add to " << IntegerA1 <<"\n\n";
cin >> IntegerA2;
cout << "\n\nYou typed in " << IntegerA2 << " and the answer is " << IntegerA1 + IntegerA2;
cout <<_getch();}
elseif(Operator == 2) {cout << "\n\nYou choose Subtraction\n";
cout << "Please type the number you want to subtract\n\n";
cin >> IntegerS1;
cout << "You typed in " << IntegerS1 << ", please type in the number you want to subtract from " << IntegerS1 <<"\n\n";
cin >> IntegerS2;
cout << "\n\nYou typed in " << IntegerS2 << " and the answer is " << IntegerS1 - IntegerS2;
cout <<_getch();}
elseif(Operator == 3){ cout << "\n\nYou choose Multiplication\n";
cout << "Please type the number you want to multiply\n\n";
cin >> IntegerM1;
cout << "You typed in " << IntegerM1 << ", please type in the number you want to multiply to " << IntegerM1 <<"\n\n";
cin >> IntegerM2;
cout << "\n\nYou typed in " << IntegerM2 << " and the answer is " << IntegerM1 * IntegerM2;
cout <<_getch();}
elseif(Operator == 4) {cout << "\n\nYou choose Division\n";
cout << "Please type the number you want to divide\n\n";
cin >> IntegerD1;
cout << "You typed in " << IntegerD1 << ", please type in the number you want to divide to " << IntegerD1 <<"\n\n";
cin >> IntegerD2;
cout << "\n\nYou typed in " << IntegerD2 << " and the answer is " << IntegerD1 / IntegerD2;
cout <<_getch();}
else {cout <<"\n\nBad Input. Quitting...";}
return 0;
}