Hi there, I am fairly new to programing and can't seem to figure out what I am doing wrong here. I am working out of a SAMS teach yourself C++ book, and am busy on a calculator.
When I compile and run the code the answer generated is not correct. It seems as if the input is not affecting the answer.
I would greatly appreciate any advise.
ThanksCode:#include <iostream> #include "PromptModule.h" #include "ErrorHandlingModule.h" using namespace std; char GetOperator(void) { char theOperator = 0; cout << "Operator: "; cin >> theOperator; } float GetOperand(void) { float theOperand = 1; cout << "Operand: "; cin >> theOperand; } float Accumulate(const char theOperator,const float theOperand) { static float myAccumulator = 0; // Initialized to 0 when the program starts switch(theOperator) { case '+': myAccumulator = myAccumulator + theOperand; break; case '-': myAccumulator = myAccumulator - theOperand; break; case '*': myAccumulator = myAccumulator * theOperand; break; case '/': myAccumulator = myAccumulator / theOperand; break; default: cout << "Please enter +,-,* or /." << endl; }; return myAccumulator; } int main(int argc, char* argv[]) { SAMSErrorHandling::Initialize(); do { try { char Operator = GetOperator(); float Operand = GetOperand(); cout << Accumulate(Operator,Operand) << endl; } catch(...) { SAMSErrorHandling::HandleNotANumberError(); }; } while (SAMSPrompt::UserWantsToContinueYOrN ("More Division?")); return 0; }
J2ke



LinkBack URL
About LinkBacks


