R
Richard Weeks
Below is a fragment from a program that calculates statistics on
x,y data. I want the user to be able to predict one or more
predicted values of y from x, given the line of best fit. I have
a procedural problem.
predict:
printf("\npredict y? (y/n): ");
if((getc(stdin)=='n')) exit(EXIT_SUCCESS);
//if((fgets(response, 1, stdin)=="n")) exit(EXIT_SUCCESS);
else
{
printf("\nenter x: ");
scanf("%lf", &xdatum);
printf("\ny = %f\n", y_int + (slope * xdatum));
fflush(stdin);
goto predict;
}
It works fine using getc, but when I use fgets execution jumps
directly into the else{} block and prompts for x without waiting
for user response to the y/n prompt. What am I doing wrong?
Richard
x,y data. I want the user to be able to predict one or more
predicted values of y from x, given the line of best fit. I have
a procedural problem.
predict:
printf("\npredict y? (y/n): ");
if((getc(stdin)=='n')) exit(EXIT_SUCCESS);
//if((fgets(response, 1, stdin)=="n")) exit(EXIT_SUCCESS);
else
{
printf("\nenter x: ");
scanf("%lf", &xdatum);
printf("\ny = %f\n", y_int + (slope * xdatum));
fflush(stdin);
goto predict;
}
It works fine using getc, but when I use fgets execution jumps
directly into the else{} block and prompts for x without waiting
for user response to the y/n prompt. What am I doing wrong?
Richard