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