Initialization#
This commit is contained in:
parent
dc81195d36
commit
bc679d629c
12
a1/program.c
12
a1/program.c
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
char line[100];
|
||||
@ -28,10 +29,7 @@ int main() {
|
||||
}
|
||||
|
||||
// Parse the line
|
||||
if (sscanf(line, "%lf%c%lf=%lf", &num1, &op, &num2, &expected_result) != 4) {
|
||||
printf("CHYBA\n");
|
||||
continue;
|
||||
}
|
||||
sscanf(line, "%lf%c%lf=%lf", &num1, &op, &num2, &expected_result);
|
||||
|
||||
// Check if the input is valid
|
||||
if (op != '+' && op != '-' && op != '*' && op != '/') {
|
||||
@ -61,8 +59,12 @@ int main() {
|
||||
break;
|
||||
}
|
||||
|
||||
// Round both result and expected_result to two decimal places
|
||||
result = round(result * 100) / 100.0;
|
||||
expected_result = round(expected_result * 100) / 100.0;
|
||||
|
||||
// Check if the result is correct
|
||||
if (((int)(result * 100 + 0.5) / 100.0) == expected_result) {
|
||||
if (result == expected_result) {
|
||||
printf("OK\n");
|
||||
} else {
|
||||
printf("ZLE\n");
|
||||
|
Loading…
Reference in New Issue
Block a user