From fc0feb846e6954e79b1895a13cb3470d358cae9a Mon Sep 17 00:00:00 2001 From: kr820js Date: Sat, 23 Mar 2024 20:12:52 +0100 Subject: [PATCH] submition10 --- a1/program.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/a1/program.c b/a1/program.c index 38ea520..4dec15e 100644 --- a/a1/program.c +++ b/a1/program.c @@ -70,7 +70,7 @@ int analizing_string(char* pointer){ memset(second_number, 0, SIZE); memset(result_nubmer, 0, SIZE); - float number1, number2, result3; + double number1, number2, result3; char operant; int i = 0; @@ -132,16 +132,23 @@ int analizing_string(char* pointer){ number2=atof(second_number); result3=atof(result_nubmer); + number1 = round(number1 *100) / 100; + number2 = round(number2 *100) / 100; + result3 = round(result3 *100) / 100; + + printf("number1 = %s, number2 = %s, result3 = %s\n", first_number, second_number, result_nubmer); + printf("number1 = %f, number2 = %f, result3 = %f\n", number1, number2, result3); + if(operant=='+' &&result3==number1+number2){ return 1; } if(operant=='-'&&(result3==number1-number2)){ return 1; } - if(operant=='*'&&(result3==number1*number2)){ + if(operant=='*'&&(result3==round((number1*number2) * 100) / 100)){ return 1; } - if(operant=='/'&&(result3==number1/number2)){ + if(operant=='/'&&(result3==round((number1/number2) * 100) / 100)){ return 1; } return 0;