From 51bfaced42f0a0561a827315efaa5333a2b5fba5 Mon Sep 17 00:00:00 2001 From: Weber Date: Thu, 28 Mar 2024 18:01:04 +0000 Subject: [PATCH] test --- a1/program.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/a1/program.c b/a1/program.c index b0dd4f1..2448485 100644 --- a/a1/program.c +++ b/a1/program.c @@ -1,6 +1,7 @@ #include #include #include +#include #define MAX_LINE_LENGTH 100 @@ -8,14 +9,23 @@ int main() { char uloha[MAX_LINE_LENGTH]; while (fgets(uloha, MAX_LINE_LENGTH, stdin) != NULL) { - if (uloha[0] == '\n') { + int i; + int isEmpty = 1; + for (i = 0; uloha[i] != '\0'; i++) { + if (uloha[i] != ' ' && uloha[i] != '\t' && uloha[i] != '\n' && uloha[i] != '\r') { + isEmpty = 0; + break; + } + } + if (isEmpty) { continue; } - int cislo1, cislo2, vysledok_zadany; + int cislo1, cislo2; + double vysledok_zadany; char operacia; - if (sscanf(uloha, "%d %c %d = %d", &cislo1, &operacia, &cislo2, &vysledok_zadany) != 4) { + if (sscanf(uloha, "%d %c %d = %lf", &cislo1, &operacia, &cislo2, &vysledok_zadany) != 4) { printf("CHYBA\n"); continue; } @@ -44,7 +54,7 @@ int main() { continue; } - if (fabs(vysledok_skutocny - round(vysledok_skutocny * 100) / 100.0) < 1e-6 && vysledok_zadany == round(vysledok_skutocny * 100) / 100.0) { + if (fabs(vysledok_skutocny - vysledok_zadany) < 1e-6) { printf("OK\n"); } else { printf("ZLE\n");