This commit is contained in:
Sadchenko 2024-03-28 23:03:39 +01:00
parent 4ce91bfee7
commit 511967b3bf

View File

@ -4,7 +4,49 @@
#include <stdbool.h> #include <stdbool.h>
#include <math.h> #include <math.h>
bool check_spaces(const char* str) {
int len = strlen(str);
bool is_operator = false;
bool is_operand = false;
for (int i = 0; i < len; ++i) {
char current_char = str[i];
if (current_char == ' ') {
if (!is_operator && !is_operand) {
return false;
}
}
else if (current_char >= '0' && current_char <= '9') {
is_operand = true;
is_operator = false;
}
else if (current_char == '+' || current_char == '-' || current_char == '*' || current_char == '/') {
is_operator = true;
is_operand = false;
}
else {
return false;
}
}
if (!is_operand) {
return false;
}
return true;
}
char* check_math_problem(const char* problem) { char* check_math_problem(const char* problem) {
if (!check_spaces(problem)) {
return "ZLE";
}
if (strlen(problem) == 0) { if (strlen(problem) == 0) {
return "CHYBA"; return "CHYBA";
} }
@ -16,6 +58,10 @@ char* check_math_problem(const char* problem) {
return "CHYBA"; return "CHYBA";
} }
if (equel != '=') {
return "CHYBA";
}
double result; double result;
switch (sing) { switch (sing) {
case '+': case '+':
@ -57,3 +103,8 @@ int main() {
return 0; return 0;
} }