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");