58 lines
1.6 KiB
C
58 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
|
|
char pole[100];
|
|
|
|
int main() {
|
|
float cislo1, cislo2, vysledok, ocakavany_vysledok;
|
|
char znamienko, rovna_sa;
|
|
|
|
while (1) {
|
|
if (fgets(pole, sizeof(pole), stdin) != NULL) {
|
|
if (sscanf(pole, "%f %c %f %c %f", &cislo1, &znamienko, &cislo2, &rovna_sa, &ocakavany_vysledok) == 5 && rovna_sa == '=') {
|
|
switch (znamienko) {
|
|
case '+':
|
|
vysledok = cislo1 + cislo2;
|
|
break;
|
|
case '-':
|
|
vysledok = cislo1 - cislo2;
|
|
break;
|
|
case '*':
|
|
vysledok = cislo1 * cislo2;
|
|
break;
|
|
case '/':
|
|
if (cislo2 != 0)
|
|
vysledok = cislo1 / cislo2;
|
|
else {
|
|
printf("ZLE\n");
|
|
return 0;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
printf("Zle znamienko!\n");
|
|
return 0;
|
|
break;
|
|
}
|
|
|
|
vysledok = roundf(vysledok * 100) / 100;
|
|
|
|
if (vysledok == ocakavany_vysledok) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("ZLE\n");
|
|
}
|
|
} else if (pole[0] == '\n') {
|
|
break;
|
|
} else {
|
|
printf("CHYBA\n");
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|