/* * * Chapter 7 * By John Stile * Purpose: * Write a program that asks an integer between 10 and 20 from the user. * If the user enteres other values which do not satisfy the condition, * prints an error message and asks for another number until the * condition is met. Use a do...while loop and if...else structure. */ #include #include int main(void) { int number; do { printf("Enter a number between 10 and 20: "); scanf("%d", &number); // read in one character getchar(); // clear input buffer printf("Testing %d\n", number); if ( ( number < 10) | (number > 20 ) )// not greater than 10 // or // not less than 20 { printf("\nbad input! %d\n",number); // scold bad input } } while ( ( number < 10) | (number > 20 ) ) ; printf("You entered %d\n", number); return 0; }