Heres a part of my code:
printf(\"\\nEnter amount of adult tickets:\");
scanf(\"%d\", &TktAdult);
while (TktAdult<0){
printf(\"\\n
The following code rejects user input that are:
positive numbers followed by non-numeric chars as handled by //3
while (1) {
printf("\nEnter amount of adult tickets: ");
if (scanf("%d", &TktAdult) < 0 || // 1
TktAdult < 0 || // 2
((next = getchar()) != EOF && next != '\n')) { // 3
clearerr(stdin);
do
next = getchar();
while (next != EOF && next != '\n'); // 4
clearerr(stdin);
printf("\nPlease enter a positive number!");
} else {
break;
}
}
Also, // 4 clears the standard input of buffered non-numeric characters following case // 3 (i.e. 123sda - scanf takes 123 but leaves 'sda' in the buffer).