diff --git a/a1/program.c b/a1/program.c index 7d7b113..0eaba28 100644 --- a/a1/program.c +++ b/a1/program.c @@ -2,6 +2,7 @@ #include #include #include +#include int main() { char line[100]; @@ -14,7 +15,7 @@ int main() { break; } - num1 = num2 = result = 0; + num1 = num2 = result = expected_result = 0; op = '\0'; // Remove any spaces between symbols @@ -57,10 +58,18 @@ int main() { result = num1 * num2; break; case '/': + if (num2 == 0) { + printf("CHYBA\n"); + continue; + } result = num1 / num2; break; } + // Round both result and expected_result to two decimal places + result = round(result * 100.0) / 100.0; + expected_result = round(expected_result * 100.0) / 100.0; + // Check if the result is correct if (result == expected_result) { printf("OK\n");