From b5ed7a6c611b70ceef5dcac4e563dd0fb0742c2a Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 11:11:29 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20du2/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du2/program.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/du2/program.c b/du2/program.c index 3ebd139..20eceda 100644 --- a/du2/program.c +++ b/du2/program.c @@ -26,7 +26,6 @@ int read_double(double *value, int coef_index) { // If no number was read or there are invalid characters if (endptr == line || *endptr != '\0') { - printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); // Corrected error message return -1; // Indicate error } @@ -36,19 +35,24 @@ int read_double(double *value, int coef_index) { int main() { double x; - // Read the value of x - if (!read_double(&x, 1)) { + // Read the value of x with special error message for invalid input + int status = read_double(&x, 1); + if (status == -1) { + printf("Nepodarilo sa nacitat zaklad x\n"); return 1; } + if (status == 0) { + return 1; // Exit if no input is provided + } double coef; double result = 0; - int coef_count = 0; // We will count coefficients starting from 0, so x^0 coefficient will be at index 0 + int coef_count = 0; // Start counting coefficients from 0 // Loop to read coefficients while (1) { coef_count++; // Increase coefficient index for each input - int status = read_double(&coef, coef_count); + status = read_double(&coef, coef_count); if (status == -1) { return 0; // Exit program if there's invalid input