From a243f41adeb3722f87aed9bb466c8524d661606a Mon Sep 17 00:00:00 2001 From: ak643du Date: Wed, 27 Mar 2024 15:26:43 +0100 Subject: [PATCH] Initialization --- a1/program.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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");