This commit is contained in:
Džubara 2024-02-27 10:13:05 +01:00
parent ebdb1ceaac
commit 5619d453a3

View File

@ -8,7 +8,9 @@
bool IsValidNumber(const char *line) { bool IsValidNumber(const char *line) {
char *endFtr; char *endFtr;
strtod(line, &endFtr); strtod(line, &endFtr);
return *endFtr == '\0'; if (endPtr == line){
return false;
}
} }
int main() { int main() {
@ -23,7 +25,6 @@ int main() {
} }
while (1) { while (1) {
printf("Zadajte polynom na %d mieste: ", coefficientIndex);
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
printf("Nepodarilo sa nacitat polynom na %d mieste. \n", coefficientIndex); printf("Nepodarilo sa nacitat polynom na %d mieste. \n", coefficientIndex);
return 1; return 1;
@ -36,11 +37,10 @@ int main() {
return 1; return 1;
} }
result = result * x; result = result * x + coeffiecientIndex;
coefficientIndex++;
} }
printf("Vysledok je: %f\n", result); printf("Vysledok je: %.2f\n", result);
return 0; return 0;
} }