fix s nespravnymi operatormi 4

This commit is contained in:
Aleš Novysedlák 2025-03-10 14:40:06 +01:00
parent e67bc5e4a8
commit a4f88b62de

View File

@ -18,6 +18,7 @@ int main() {
int index = 0; int index = 0;
while (fgets(buffer, sizeof(buffer), stdin) != NULL) { while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
int error = 0; int error = 0;
int operator_count = 0;
if (buffer[0] == '\n') break; if (buffer[0] == '\n') break;
index = 0; index = 0;
eq_index = 0; eq_index = 0;
@ -47,6 +48,7 @@ int main() {
equation[eq_index][0] = buffer[index]; equation[eq_index][0] = buffer[index];
equation[eq_index][1] = '\0'; equation[eq_index][1] = '\0';
eq_index++; eq_index++;
operator_count++;
} }
index++; index++;
} }
@ -54,6 +56,12 @@ int main() {
equation[eq_index][eq_operand_length] = '\0'; equation[eq_index][eq_operand_length] = '\0';
eq_index++; eq_index++;
} }
if (operator_count < 2) {
error = 1;
strcpy(output[output_length], "CHYBA");
output_length++;
}
float total = 0.0; float total = 0.0;
char last_operator = '+'; char last_operator = '+';
int sign = 0; int sign = 0;