From 7b88ef30239e79756b1cf9a0d7ac48d0e7b87118 Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Wed, 20 Mar 2024 15:32:08 +0100 Subject: [PATCH] divide fix v.2 --- a1/program.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/a1/program.c b/a1/program.c index 2ad0c08..27086d4 100644 --- a/a1/program.c +++ b/a1/program.c @@ -1,17 +1,16 @@ #include #include -#include +#include char pole[100]; int main() { - float cislo1, cislo2, vysledok; + float cislo1, cislo2, vysledok, ocakavany_vysledok; char znamienko, rovna_sa; - int ocakavany_vysledok; while (1) { if (fgets(pole, sizeof(pole), stdin) != NULL) { - if (sscanf(pole, "%f %c %f %c %d", &cislo1, &znamienko, &cislo2, &rovna_sa, &ocakavany_vysledok) == 5 && rovna_sa == '=') { + if (sscanf(pole, "%f %c %f %c %f", &cislo1, &znamienko, &cislo2, &rovna_sa, &ocakavany_vysledok) == 5 && rovna_sa == '=') { switch (znamienko) { case '+': vysledok = cislo1 + cislo2; @@ -28,14 +27,16 @@ int main() { else { printf("Nulou sa nedeli!\n"); return 0; + break; } break; default: printf("Zle znamienko!\n"); return 0; + break; } - if (fabs(vysledok - (float)ocakavany_vysledok) < 0.0001) { + if (fabs(vysledok - ocakavany_vysledok) < 0.0001) { printf("OK\n"); } else { printf("ZLE\n"); @@ -52,3 +53,4 @@ int main() { return 0; } +