From bd8856e0bae08977a7ef3d0344a89de034a045cf Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Tue, 5 Mar 2024 18:57:34 +0100 Subject: [PATCH] added errors --- cv3/program.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 9715c5e..9f7bda0 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -3,18 +3,37 @@ int main() { float pole[50]; int opakovania = 0; - float cislo; + float cislo = 0; + float skenovanie; + int zla_hodnota = 0; + int zly_index = -1; while (opakovania < 50) { - if (scanf("%f", &cislo) == EOF) { - break; + skenovanie = scanf("%f", &cislo); + + if (skenovanie == 1) { + pole[opakovania] = cislo; + opakovania++; + } else if (skenovanie == EOF) { + if (zla_hodnota) { + printf("Nepodarilo sa nacitat polynom na %d. mieste.\n", zly_index); + return 1; + } else { + break; + } + } else { + zla_hodnota = 1; + zly_index = opakovania; + while (getchar() != '\n'); } - pole[opakovania] = cislo; - opakovania++; + } + + if (opakovania == 0) { + printf("Nepodarilo sa nacitat hodnotu X.\n"); + return 1; } float vysledok = pole[1]; - for (int i = 2; i < opakovania; ++i) { vysledok = vysledok * pole[0] + pole[i]; }