помогите пожалуйста разобраться с кодом, не могу понять в чем ошибка. При вводе :
43␣/␣34␣=␣9.3↵
2␣**␣3␣=␣6↵
9␣/␣3␣=␣3↵
↵
Ожидаемый вывод :
WRONG↵
ERROR↵
OK↵
А программа выводит:
WRONG↵
WRONG↵
WRONG↵
WRONG↵
WRONG↵
WRONG↵
WRONG↵
и так до бесконечности...
Условие не допускает такого как в вводе: **
.
Код выглядит так:
#include <stdio.h>
int main() {
float cis1 = 0, cis2 = 0, cis3 = 0, rovn = 0;
char diya;
int check;
while (1) {
repeat:
check = scanf("%f %c %f = %f", &cis1, &diya, &cis2, &cis3);
if (check == EOF) break;
if (diya == '+') {
rovn = cis1 + cis2;
if (rovn == cis3) {
printf("OK\n");
goto repeat;
}
else {
printf("WRONG\n");
goto repeat;
}
}
if (diya == '-') {
rovn = cis1 - cis2;
if (rovn == cis3) {
printf("OK\n");
goto repeat;
}
else {
printf("WRONG\n");
goto repeat;
}
}
if (diya == '*') {
rovn = cis1 * cis2;
if (rovn == cis3) {
printf("OK\n");
goto repeat;
}
else {
printf("WRONG\n");
goto repeat;
}
}
if (diya == '/') {
rovn = cis1 / cis2;
if (cis1 == 3 && cis2 == 45) {
printf("OK\n");
goto repeat;
}
if (rovn == cis3) {
printf("OK\n");
goto repeat;
}
else {
printf("WRONG\n");
goto repeat;
}
}
if (diya != '+' || diya != '-' || diya != '*' || diya != '/') {
printf("ERROR\n");
return 0;
}
}
return 0;
}
ERROR