a1
This commit is contained in:
parent
94f1f205be
commit
f936322d83
29
a1/program.c
29
a1/program.c
@ -25,34 +25,49 @@ struct vzorec{
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
int results[SIZE];
|
||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
char znaky[] = "+-*/";
|
char znaky[] = "+-*/";
|
||||||
memset(line,0,SIZE);
|
memset(line,0,SIZE);
|
||||||
struct vzorec funkcia[SIZE];
|
struct vzorec funkcia[SIZE];
|
||||||
memset(funkcia,0,SIZE);
|
memset(funkcia,0,SIZE);
|
||||||
char* pEnd;
|
char* pEnd;
|
||||||
|
int counter = 0;
|
||||||
while (fgets(line,SIZE,stdin) && line[0] != '\n'){
|
while (fgets(line,SIZE,stdin) && line[0] != '\n'){
|
||||||
if(line == NULL){
|
if(line == NULL){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int n = sscanf(line, "%lf %c %lf %c %lf", &funkcia->x, &funkcia->znak1, &funkcia->y, &funkcia->znak2, &funkcia->result);
|
int n = sscanf(line, "%lf %c %lf %c %lf", &funkcia->x, &funkcia->znak1, &funkcia->y, &funkcia->znak2, &funkcia->result);
|
||||||
if(checkZnaka(znaky, funkcia->znak1) == true || funkcia->znak2 != '='){
|
if(checkZnaka(znaky, funkcia->znak1) == true || funkcia->znak2 != '='){
|
||||||
printf("CHYBA\n");
|
results[counter] = 1;
|
||||||
return 0;
|
counter++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
double r1 = (round(funkcia->x*10) + round(funkcia->y*10))/10;
|
double r1 = (round(funkcia->x*10) + round(funkcia->y*10))/10;
|
||||||
double r2 = (round(funkcia->x*10) - round(funkcia->y*10))/10;
|
double r2 = (round(funkcia->x*10) - round(funkcia->y*10))/10;
|
||||||
double r3 = (round(funkcia->x*10) * round(funkcia->y))/10;
|
double r3 = (round(funkcia->x*10) * round(funkcia->y))/10;
|
||||||
double r4 = (round(funkcia->x*10) / round(funkcia->y))/10;
|
double r4 = (round(funkcia->x*10) / round(funkcia->y))/10;
|
||||||
if(funkcia->result != r1 && funkcia->result != r2 && funkcia->result != r3 && funkcia->result != r4){
|
if(funkcia->result != r1 && funkcia->result != r2 && funkcia->result != r3 && funkcia->result != r4){
|
||||||
printf("ZLE\n");
|
results[counter] = 2;
|
||||||
return 0;
|
counter++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printf("OK\n");
|
results[counter] = 3;
|
||||||
return 0;
|
counter++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
printf("x: %d, znak1: %c, y: %d, znak2: %c, result: %d\n", funkcia->x, funkcia->znak1, funkcia->y, funkcia->znak2, funkcia->result);
|
}
|
||||||
|
for(int i = 0; i <= counter;i++){
|
||||||
|
if(results[i] == 1){
|
||||||
|
printf("CHYBA\n");
|
||||||
|
}
|
||||||
|
if(results[i] == 2){
|
||||||
|
printf("ZLE\n");
|
||||||
|
}
|
||||||
|
if(results[i] == 3){
|
||||||
|
printf("OK\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user