What I'd suggest is something like this:
Code:
#include <stdio.h>
int main(void) {
int a, b;
char line[BUFSIZ];
printf("Please enter any two numbers:\n> ");
while (fgets(line, sizeof(line), stdin)) {
if (sscanf(line, "%d %d", &a, &b) == 2) {
printf("The sum of two numbers is: %d\n", a + b);
break;
}
printf("You need to enter two integer values\n> ");
}
return 0;
}
The idea is that you read a line of input from the user, so you don't have to worry about discarding invalid input. (Well, technically you still have to handle a case where the user enters more input than can fit in the array of char, but you can do that as a more advanced exercise.)
Then, to determine if the input is valid, you parse the line read with sscanf and check the return value.