The whole program:
- Code: Select all
// CalculatorApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
int choice;
int num1;
int num2;
int num3;
int answer;
cout<<"Do you want to add, subtract, or multiply?"<<endl
<<"1: add"
<<endl
<<"2: subtract"
<<endl
<<"3: multiply"
<<endl
<<"4: divide"
<<endl
<<"5: exponent"
<<endl;
cin>>choice;
if (choice < 1 || choice > 5)
{
cout<<"Enter 1, 2, 3, 4 or 5 next time!"<<endl;
choice = 0;
}
if (choice == 1)
{
choice = 0;
cout<<"How many numbers are there?"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"You need a calculator to add one number? Moron..."<<endl;
break;
case 2: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
answer = num1+num2;
cout<<"The answer is: "<<answer<<endl;
break;
case 3: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
cout<<"Enter number 3: "<<endl;
cin>>num3;
answer = num1+num2+num3;
cout<<"The answer is: "<<answer<<endl;
break;
default: cout<<"Sorry, but the calculator is unable to process your request at this time.\n"
<<"Please wait for an updated version or try again."
<<endl;
}
}
if (choice == 2)
{
choice = 0;
cout<<"How many numbers are there?"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"You need a calculator to subtract one number? Moron..."<<endl;
break;
case 2: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
answer = num1-num2;
cout<<"The answer is: "<<answer<<endl;
break;
case 3: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
cout<<"Enter number 3: "<<endl;
cin>>num3;
answer = num1-num2-num3;
cout<<"The answer is: "<<answer<<endl;
break;
default: cout<<"Sorry, but the calculator is unable to process your request at this time.\n"
<<"Please wait for an updated version or try again."
<<endl;
}
}
if (choice == 3)
{
choice = 0;
cout<<"How many numbers are there?"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"You need a calculator to multiply one number? Moron..."<<endl;
break;
case 2: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
answer = num1*num2;
cout<<"The answer is: "<<answer<<endl;
break;
case 3: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
cout<<"Enter number 3: "<<endl;
cin>>num3;
answer = num1*num2*num3;
cout<<"The answer is: "<<answer<<endl;
break;
default: cout<<"Sorry, but the calculator is unable to process your request at this time.\n"
<<"Please wait for an updated version or try again."
<<endl;
}
}
if (choice == 4)
{
choice = 0;
cout<<"How many numbers are there?"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"You need a calculator to divide one number? Moron..."<<endl;
break;
case 2: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
answer = num1/num2;
cout<<"The answer is: "<<answer<<endl;
break;
case 3: cout<<"Enter number 1: "<<endl;
cin>>num1;
cout<<"Enter number 2: "<<endl;
cin>>num2;
cout<<"Enter number 3: "<<endl;
cin>>num3;
answer = num1/num2/num3;
cout<<"The answer is: "<<answer<<endl;
break;
default: cout<<"Sorry, but the calculator is unable to process your request at this time.\n"
<<"Please wait for an updated version or try again."
<<endl;
}
}
if (choice == 5)
{
cout<<"Enter the number: "<<endl;
cin>>num1;
cout<<"Enter the exponent: "<<endl;
cin>>num2;
if ((num1*num1)*num2 == num1*4)
{
answer = num1*2;
cout<<"The answer is: "<<answer<<endl;
}
if ((num1*num1)*2)
{
answer = num1*num1;
cout<<"The answer is: "<<answer<<endl;
}
else
{
answer = (num1*num1)*(num2*num1);
cout<<"The answer is: "<<answer<<endl;
}
}
system("PAUSE");
return 0;
}
The snippet:
- Code: Select all
if (choice == 5)
{
cout<<"Enter the number: "<<endl;
cin>>num1;
cout<<"Enter the exponent: "<<endl;
cin>>num2;
if ((num1*num1)*num2 == num1*4)
{
answer = num1*2;
cout<<"The answer is: "<<answer<<endl;
}
if ((num1*num1)*2)
{
answer = num1*num1;
cout<<"The answer is: "<<answer<<endl;
}
else
{
answer = (num1*num1)*(num2*num1);
cout<<"The answer is: "<<answer<<endl;
}
}


