Initialization

This commit is contained in:
Kozar 2024-03-27 15:26:43 +01:00
parent e1caca1f23
commit a243f41ade

View File

@ -2,6 +2,7 @@
#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];
@ -14,7 +15,7 @@ int main() {
break; break;
} }
num1 = num2 = result = 0; num1 = num2 = result = expected_result = 0;
op = '\0'; op = '\0';
// Remove any spaces between symbols // Remove any spaces between symbols
@ -57,10 +58,18 @@ int main() {
result = num1 * num2; result = num1 * num2;
break; break;
case '/': case '/':
if (num2 == 0) {
printf("CHYBA\n");
continue;
}
result = num1 / num2; result = num1 / num2;
break; 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 // Check if the result is correct
if (result == expected_result) { if (result == expected_result) {
printf("OK\n"); printf("OK\n");