Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
