Обновить du2/program.c
This commit is contained in:
parent
8d455bfe3a
commit
b5ed7a6c61
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user