This commit is contained in:
Weber 2024-03-28 18:29:54 +00:00
parent ff00ea7f21
commit b750faf156

View File

@ -9,6 +9,7 @@ int main() {
char uloha[MAX_LINE_LENGTH]; char uloha[MAX_LINE_LENGTH];
while (fgets(uloha, MAX_LINE_LENGTH, stdin) != NULL) { while (fgets(uloha, MAX_LINE_LENGTH, stdin) != NULL) {
int i; int i;
int isEmpty = 1; int isEmpty = 1;
for (i = 0; uloha[i] != '\0'; i++) { for (i = 0; uloha[i] != '\0'; i++) {
@ -17,15 +18,16 @@ int main() {
break; break;
} }
} }
if (isEmpty) { if (isEmpty) {
printf("OK\n");
continue; continue;
} }
double cislo1, cislo2, vysledok_zadany; int cislo1, cislo2;
double vysledok_zadany;
char operacia; char operacia;
if (sscanf(uloha, "%lf %c %lf = %lf", &cislo1, &operacia, &cislo2, &vysledok_zadany) != 4) { if (sscanf(uloha, "%d %c %d = %lf", &cislo1, &operacia, &cislo2, &vysledok_zadany) != 4) {
printf("CHYBA\n"); printf("CHYBA\n");
continue; continue;
} }
@ -44,10 +46,10 @@ int main() {
break; break;
case '/': case '/':
if (cislo2 == 0) { if (cislo2 == 0) {
printf("ZLE\n"); printf("CHYBA\n");
continue; continue;
} }
vysledok_skutocny = cislo1 / cislo2; vysledok_skutocny = (double) cislo1 / cislo2;
break; break;
default: default:
printf("CHYBA\n"); printf("CHYBA\n");