Initialization#
This commit is contained in:
parent
a7e68d397f
commit
272be6c4b2
15
a1/program.c
15
a1/program.c
@ -8,8 +8,14 @@ int main() {
|
|||||||
double num1, num2, result, expected_result;
|
double num1, num2, result, expected_result;
|
||||||
char op;
|
char op;
|
||||||
|
|
||||||
// Read the input line
|
while (fgets(line, sizeof(line), stdin) != NULL) {
|
||||||
fgets(line, sizeof(line), stdin);
|
if (line[0] == '\n') {
|
||||||
|
// Stop when the user enters a blank line
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
num1 = num2 = result = 0;
|
||||||
|
op = '\0';
|
||||||
|
|
||||||
// Remove any spaces between symbols
|
// Remove any spaces between symbols
|
||||||
for (int i = 0; line[i] != '\0'; i++) {
|
for (int i = 0; line[i] != '\0'; i++) {
|
||||||
@ -27,13 +33,13 @@ int main() {
|
|||||||
// Check if the input is valid
|
// Check if the input is valid
|
||||||
if (op != '+' && op != '-' && op != '*' && op != '/') {
|
if (op != '+' && op != '-' && op != '*' && op != '/') {
|
||||||
printf("CHYBA\n");
|
printf("CHYBA\n");
|
||||||
return 1;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for division by zero
|
// Check for division by zero
|
||||||
if (op == '/' && num2 == 0) {
|
if (op == '/' && num2 == 0) {
|
||||||
printf("ZLE\n");
|
printf("ZLE\n");
|
||||||
return 0;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the calculation
|
// Perform the calculation
|
||||||
@ -58,6 +64,7 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
printf("ZLE\n");
|
printf("ZLE\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user