This commit is contained in:
Sadchenko 2024-03-28 23:50:09 +01:00
parent 125818f09f
commit 6c2fc4d6d8

View File

@ -7,6 +7,7 @@
bool check_spaces(const char* str) { bool check_spaces(const char* str) {
int len = strlen(str); int len = strlen(str);
bool result_found = false;
for (int i = 0; i < len - 1; ++i) { for (int i = 0; i < len - 1; ++i) {
if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/') { if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/') {
@ -17,17 +18,16 @@ bool check_spaces(const char* str) {
if (str[i + 1] != ' ') if (str[i + 1] != ' ')
return false; return false;
} }
if (isdigit(str[i]) && isspace(str[i + 1])) {
result_found = true;
}
} }
if (str[len - 2] == '+' || str[len - 2] == '-' || str[len - 2] == '*' || str[len - 2] == '/') if (str[len - 2] == '+' || str[len - 2] == '-' || str[len - 2] == '*' || str[len - 2] == '/')
return false; return false;
return result_found;
if (isdigit(str[len - 2]) && str[len - 1] == ' ')
return false;
return true;
} }
char* check_math_problem(const char* problem) { char* check_math_problem(const char* problem) {
@ -50,11 +50,6 @@ char* check_math_problem(const char* problem) {
return "CHYBA"; return "CHYBA";
} }
// Проверяем, что после результата нет пробела
if (strchr(problem, '=') - strchr(problem, ' ') == 2) {
return "CHYBA";
}
double result; double result;
switch (sing) { switch (sing) {
case '+': case '+':
@ -99,3 +94,6 @@ int main() {