Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can some one help me the math in my code dose not work when i press the equal button it just clears the operation and
can some one help me the math in my code dose not work when i press the equal button it just clears the operation and anything that follows i cant sema to fix itvoid CalFrame::OnButtonClickedwxCommandEvent& event
int buttonId event.GetId;
wxString buttonText;
if buttonId IDBUTTON && buttonId IDBUTTON
buttonText wxString::Formatc buttonId IDBUTTON;
else
switch buttonId
case IDBUTTONPLUS:
buttonText ;
break;
case IDBUTTONMINUS:
buttonText ;
break;
case IDBUTTONMULTIPLY:
buttonText ;
break;
case IDBUTTONDIVIDE:
buttonText ;
break;
case IDBUTTONMOD:
buttonText ;
break;
case IDBUTTONDECIMAL:
buttonText ;
break;
case IDBUTTONCLEAR:
OnClearButtonClickevent;
return;
break;
case IDBUTTONEQUAL:
buttonText ;
OnCalculateevent;
return;
break;
case IDBUTTONTAN:
buttonText "TAN";
break;
case IDBUTTONSIN:
buttonText "SIN";
break;
case IDBUTTONCON:
buttonText "CON";
break;
case IDBUTTONNEGATIVE:
buttonText ;
break;
case IDBUTTONBACKSPACE:
OnBackspaceevent;
return;
break;
textControlAppendTextbuttonText;
void CalFrame::OnClearButtonClickwxCommandEvent& event
textControlClear;
void CalFrame::OnCalculatewxCommandEvent& event
wxString expression textControlGetValue;
double result;
if EvaluateExpressionexpression result
textControlSetValuewxString::Formatg result;
else
textControlSetValueError;
void CalFrame::OnBackspacewxCommandEvent& event
wxString currentValue textControlGetValue;
if currentValue.empty
currentValue.RemoveLast;
textControlSetValuecurrentValue;
bool CalFrame::EvaluateExpressionconst wxString & expression, double& result
if expressionempty
return false;
std::istringstream issexpressionToStdString;
std::vector tokens;
std::string token;
while iss token
tokens.pushbacktoken;
if tokenssize
return false;
try
result std::stodtokens;
for sizet i ; i tokens.size; i
std::string op tokensi;
double nextNum std::stodtokensi ;
if op
result nextNum;
else if op
result nextNum;
else if op
result nextNum;
else if op
result nextNum;
return true;
catch const std::exception&
return false;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started