69 lines
1.5 KiB
C
69 lines
1.5 KiB
C
#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;
|
|
char vysledky[50][50]; // pole pre ukladanie vysledkov
|
|
int pocet = 0;
|
|
|
|
while (1) {
|
|
char* a = fgets(pole, 100, stdin);
|
|
|
|
if (pole[0] == '\n') { //ci je riadok prazdny, ci sa stlacil enter
|
|
break;
|
|
}
|
|
|
|
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++;
|
|
}
|
|
|
|
//vypis vysledkov
|
|
for (int i = 0; i < pocet; i++) {
|
|
printf("%s\n", vysledky[i]);
|
|
}
|
|
|
|
return 0;
|
|
} |