void Calculator
::calculation(QString &operation,
QString &text_display
) {
QString a_string
= "", b_string
= "", result_string
= "", temp_string
= "";
double a, b, result;
int position, i, j;
position = operation.indexOf("*", 0) ;
for( i = position - 1; i >= 0 ; i-- )
{
if( operation.at( i ) == '*' || operation.at( i ) == '/' || operation.at( i ) == '+' || operation.at( i ) == '-' )
break;
temp_string = a_string;
a_string = operation.at( i ) + temp_string;
}
ui.display->setText( a_string ); //displays a_string on QLineEdit
}
void Calculator::calculation(QString &operation, QString &text_display)
{
QString a_string = "", b_string = "", result_string = "", temp_string = "";
double a, b, result;
int position, i, j;
position = operation.indexOf("*", 0) ;
for( i = position - 1; i >= 0 ; i-- )
{
if( operation.at( i ) == '*' || operation.at( i ) == '/' || operation.at( i ) == '+' || operation.at( i ) == '-' )
break;
temp_string = a_string;
a_string = operation.at( i ) + temp_string;
}
ui.display->setText( a_string ); //displays a_string on QLineEdit
}
To copy to clipboard, switch view to plain text mode
Basically this function has to extract a number placed before '*' operator.
When operation = "3+56*35" a_string = "56" and it works correctly. But when operation="56*35" (without any operator before "56" - that is importanat) it multiplies extraced 56 three times and a_string = "565656". I've been thinking for a few hours about that and the problem still exists.
Thanks for help.
Bookmarks