56 lines
1.6 KiB
C
56 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
char pole[100];
|
|
|
|
int main() {
|
|
float cislo1, cislo2, 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 == '=') {
|
|
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("Nulou sa nedeli!\n");
|
|
return 0;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
printf("Zle znamienko!\n");
|
|
return 0;
|
|
break;
|
|
}
|
|
|
|
if ((int)vysledok == ocakavany_vysledok) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("ZLE\n");
|
|
}
|
|
} else if (pole[0] == '\n') {
|
|
break;
|
|
} else {
|
|
printf("CHYBA\n");
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|