We could truncate the input to 2 digits but that is NOT what the question asked. It said inputs of more than 2 digits are to be ignored.
Additionally, the problem with simply restricting the number of digits input, is that any truncated digits are taken by the next input. So for example with
scanf("%2d",&myNum);
if I enter 678
the 8
remains in the buffer and is read for the next input. We could clear the input buffer but that is not what the question asked: you don't want numbers truncated to 2 digits, you want them ignored.
Here is my answer, which reads the digits as a text string and rejects those which do not have 2 digits, and those that are not digits.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
int myNum;
int c;
char str[4];
do {
myNum = 0;
printf("Enter number: ");
scanf("%3s",str);
while((c = getchar()) != '\n' && c != EOF); // flush the input
if (strlen(str) != 2 || !isdigit(str[0]) || !isdigit(str[1]))
continue;
if (sscanf(str, "%d", &myNum) != 1)
continue;
printf("You entered %d\n\n", myNum);
} while (myNum != 10);
return 0;
}
Sample session:
Enter number: 42
You entered 42
Enter number: 678
Enter number: 1
Enter number: 10
You entered 10
You can see thet 678
and 1
were not accepted.