I am trying to read three doubles from a user's input on the command line. However, my error checking is something to be desired. If I don't enter the correct number of doubles or don't enter a double the program goes into an infinite loop. Here is the main which is handling the I/O:
Code:int main() { double a, b, c, x1, x2; int qret, count; while(1) { printf("Enter variables for quadratic equation: "); if( (count = scanf("%lf %lf %lf", &a, &b, &c)) != 3) { printf("Invalid Input: Format Is <double> <double> <double>\n"); printf("%d \n", count); } else if((qret = qsolver(a, b, c, &x1, &x2)) == 3) { printf("Error Value: %d\n", qret); printf("X1 = %lf X2 = %lf\n\n", x1, x2); } } return 0; }



LinkBack URL
About LinkBacks



