#include <iostream>
#include <cstdlib> //needed for system("PAUSE");
#include <ctype.h> //needed for the tolower() function
int main(){
char equation[3];
int result;
bool wantsToContinue = true;
char yesOrNo;
equationPrompt:
std::cout << "Enter Equation: " << std::endl;
std::cin >> equation;
while(wantsToContinue){
switch(equation[1]){
case '+':
result = int(equation[0]) + int(equation[2]);
break;
case '-':
result = int(equation[0]) + int(equation[2]);
break;
case '*':
result = int(equation[0]) + int(equation[2]);
break;
case '/':
result = int(equation[0]) + int(equation[2]);
break;
}
std::cout << std::endl << "Your answer is " << result << std::endl;
exitPrompt:
std::cout << "Exit? Y/N: ";
std::cin >> yesOrNo;
if(tolower(yesOrNo) == 'n'){
wantsToContinue = true;
goto equationPrompt;
}
else if (tolower(yesOrNo) == 'y')
wantsToContinue = false;
else{
std::cout << std::endl << "Unknown response." << std::endl;
goto exitPrompt;
}
}
std::cout << result << std::endl;
system("PAUSE");
return 0;
}
Edited by Airplaneman19, 16 August 2011 - 01:13 PM.


Sign In
Create Account

Back to top









