diff --git a/du2/program.c b/du2/program.c index 621c137..3ebd139 100644 --- a/du2/program.c +++ b/du2/program.c @@ -37,15 +37,9 @@ int main() { double x; // Read the value of x - int status = read_double(&x, 1); - if (status == -1) { - // If x is invalid, print a specific error and exit - printf("Nepodarilo sa nacitat zaklad x\n"); + if (!read_double(&x, 1)) { return 1; } - if (status == 0) { - return 1; // Exit if no input is provided - } double coef; double result = 0; @@ -54,7 +48,7 @@ int main() { // Loop to read coefficients while (1) { coef_count++; // Increase coefficient index for each input - status = read_double(&coef, coef_count + 1); // coef_count + 1 for correct indexing + int status = read_double(&coef, coef_count); if (status == -1) { return 0; // Exit program if there's invalid input @@ -67,7 +61,7 @@ int main() { break; } - result = result * x + coef; // Apply Horner's method for polynial evaluation + result = result * x + coef; // Apply Horner's method for polynomial evaluation } // Print the result