// Calculator Sim
// 17 February 2013
//
// Chapter 6
// Assignment 4, Part 1
#include <iostream>
usingnamespace std;
int main()
{
// Declare variables
int first = 0;
int second = 0;
char mathOp = ' ';
int result = 0;
// Enter the first number to be used
cout << "This program will simulate a calculator using integers and simple math. " << endl ;
cout << "Please enter the first integer (whole number) to be used in the calculation: " << endl ;
cin >> first;
// Enter the operator
cout << "Please enter the operator sign. Use + for addition, - for subtraction, * for multiplication, or / for division." << endl ;
cin >> mathOp;
// Enter the second number to be used
cout << "Please enter the second integer (whole number) to be used in the calculation: " << endl ;
cin >> second;
// Prevent division by zero to avoid ripping the fabric of space and time
if (second == 0)
{
cout << "Error, division by zero not allowed." << endl;
exit(0);
}
// end if
// Calculation
// Determine the operation and implement
// Multiplication
if (mathOp == '*')
{result = first * second;}
// Division
elseif (mathOp == '/')
{result = first / second;}
// Addition
elseif (mathOp == '+')
{result = first + second;}
// Subtraction
elseif (mathOp == '-')
{result = first - second;}
// Reject erroneous input for the operator
else // default
{cout << "Input error for the operator. Please select one of the choices above for the operator next time." << endl;}
// end if
// Display result
cout << result << endl;
}
Once I actually compiled and ran the program it worked for me. I kept getting those errors while working on the program. MSVS is more complicated than C++.