Quote Originally Posted by flp1969 View Post
When data on a stream cannot be converted it stays in the stream buffer. When you type 'bob' scanf() will return 0 and "bob\n" will stay in the stdin's buffer... the latter scanf() will read 1 char leaving "ob\n" in the buffer... In the next iteration, "ob" will cause scanf() to fail and the latter scanf() will leave "b\n"... Third interation: scanf() will fail and the second scanf() will get it, leavind only '\n' on buffer.

Probably is best to do something like this:
Code:
char buffer[1024];
double value;
int valid=0;

while ( ! valid )
{
  printf( "Enter value: " ); 
  fflush( stdout );  // to garantee stdout buffer flushing.

  if ( fgets( buffer, sizeof buffer, stdin ) )
    valid = sscanf( buffer, "%lf", &value ) == 1;
}
Very good answer; I was not able to think of a simple answer based on the OP code; I did not think of the idea of starting from scratch to solve the issue.
And, I would have used an function that the OP might not yet know how to write an user defined function.

Tim S.