2024-03-28 18:44:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
|
|
|
char pole[100];
|
|
|
|
double cislo1;
|
|
|
|
double cislo2;
|
|
|
|
double vysledok;
|
|
|
|
char znamienko;
|
|
|
|
char* token;
|
2024-03-28 20:45:33 +00:00
|
|
|
char vysledky[50][50]; // pole pre ukladanie vysledkov
|
|
|
|
int pocet = 0;
|
2024-03-28 18:44:42 +00:00
|
|
|
|
2024-03-28 20:45:33 +00:00
|
|
|
while (1) {
|
|
|
|
char* a = fgets(pole, 100, stdin);
|
2024-03-28 18:44:42 +00:00
|
|
|
|
2024-03-28 20:45:33 +00:00
|
|
|
if (pole[0] == '\n') { //ci je riadok prazdny, ci sa stlacil enter
|
2024-03-28 18:44:42 +00:00
|
|
|
break;
|
2024-03-28 20:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
token = strtok(pole, " "); //rozdelenie retazca podla medzier
|
|
|
|
cislo1 = atof(token); // premena stringu na desatinne cislo a priradenie cislu1
|
|
|
|
token = strtok(NULL, " "); //pokracovanie v rozdelovani retazca
|
|
|
|
znamienko = token[0]; //vrati ukazatel na nasledujuci token, cize znamienko
|
|
|
|
token = strtok(NULL, " =\n");
|
|
|
|
cislo2 = atof(token);
|
|
|
|
token = strtok(NULL, " =\n");
|
|
|
|
vysledok = atof(token);
|
|
|
|
|
|
|
|
double realny;
|
|
|
|
|
|
|
|
switch (znamienko){
|
|
|
|
case '+':
|
|
|
|
realny = cislo1 + cislo2;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
realny = cislo1 - cislo2;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
realny = cislo1 * cislo2;
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
realny = cislo1 / cislo2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("CHYBA\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (realny == vysledok){
|
|
|
|
strcpy(vysledky[pocet], "OK"); //kopiruje vysledok do pola vysledky
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
strcpy(vysledky[pocet], "ZLE");
|
|
|
|
}
|
|
|
|
pocet++;
|
2024-03-28 18:44:42 +00:00
|
|
|
}
|
2024-03-28 20:45:33 +00:00
|
|
|
|
|
|
|
//vypis vysledkov
|
|
|
|
for (int i = 0; i < pocet; i++) {
|
|
|
|
printf("%s\n", vysledky[i]);
|
2024-03-28 18:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|