From ab77dc0676a5bcf87ba4e1edc0fdcf265944afe7 Mon Sep 17 00:00:00 2001 From: Artem Horbunov Date: Thu, 2 Apr 2020 18:08:51 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu4/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du4/program.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/du4/program.c b/du4/program.c index ca682f1..ba68395 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,22 +1,24 @@ #include int main(){ - char read[1000000]; - scanf("%[^\n]", read); - float num1, num2, answer; - char action; - sscanf(read, "%f %c %f %*c %f", &num1, &action, &num2, &answer); - if(action != '/' && action != '*' && action != '-' && action != '+'){ - printf("CHYBA\n"); - return 0; + while(1){ + char read[1000000]; + scanf("%[^\n]", read); + float num1, num2, answer; + char action; + sscanf(read, "%f %c %f %*c %f", &num1, &action, &num2, &answer); + if(action != '/' && action != '*' && action != '-' && action != '+'){ + printf("CHYBA\n"); + return 0; + } + float check = (action == '/') ? num1 / num2 : (action == '*') ? num1 * num2 : (action == '+') ? num1 + num2 : num1 - num2; + check *= 100000; + int tmp = check; + check = (float) tmp / 100000; + answer *= 100000; + tmp = answer; + answer = (float) tmp / 100000; + printf("%s\n", (check == answer) ? "OK" : "ZLE"); + //printf("%f\n", check); } - float check = (action == '/') ? num1 / num2 : (action == '*') ? num1 * num2 : (action == '+') ? num1 + num2 : num1 - num2; - check *= 100000; - int tmp = check; - check = (float) tmp / 100000; - answer *= 100000; - tmp = answer; - answer = (float) tmp / 100000; - printf("%s\n", (check == answer) ? "OK" : "ZLE"); - //printf("%f\n", check); }