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