| control/input-validation-ex.c - Eksempel på input validation loop. | Lektion 4 - slide 10 : 14 Program 8 |
/* An input validation loop with do-while */
#include <stdio.h>
int main(void) {
int number;
/* Repeated prompting with input validation */
do {
printf("Enter a non-negative integer: ");
scanf("%d", &number);
} while (number < 0);
/* Printing the result */
printf("Here it is: %d\n", number);
return 0;
}