diff --git a/du2/program.c b/du2/program.c index f6d9361..10911a5 100644 --- a/du2/program.c +++ b/du2/program.c @@ -13,7 +13,7 @@ int read_double(double *num){ char *endptr; *num = strtod(line, &endptr); if(endptr == line || (*endptr != '\0' && *endptr != '\n')){ - return -1; + return 0; } return 1; } @@ -21,14 +21,13 @@ int read_double(double *num){ int main(){ double x, coef, result = 0.0; int coef_index = 0; - int read_status; - if((read_status = read_double(&x)) != 1){ + if(!read_double(&x)){ printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n"); - return 1; + return 0; } - while((read_status = read_double(&coef)) == 1){ + while(read_double(&coef)){ if(coef_index == 0){ result = coef; }else{ @@ -38,15 +37,15 @@ int main(){ } if(read_status == -1){ - printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index + 1); return 0; } if(coef_index == 0){ printf("Chyba: Nepodarilo sa nacitat ziadne koeficienty.\n"); - return 1; + return 0; } - printf("Vysledok je: %.2f\n", result); + printf("Vysledok je: %.2f\n", round(result * 100) / 100); return 0; -} +} \ No newline at end of file