Originally Posted by
lmanukyan
I use _getch() and scanf_s() because my compiler updated and won't let me use the other version of these.
What about this? Still doesn't work and breaks
Matticus corrected, thanks.
I'm not sure whether checking the type of input is right or not.
If there was a time to check the input, it was when scanf_s() was returning. (Are you required to use scanf_s()? If it isn't a school rule, you ought to #define _CRT_SECURE_NO_DEPRECATE) You could, for example, do this for each num:
Code:
for (;;) {
int ch, result = scanf_s ("%d%c", &num[i], &trail);
if (result != 2 || trail != '\n') {
printf ("Please enter a valid integer.\n");
while ((ch = getchar()) != '\n' && ch != EOF) ;
}
else break;
}
Code:
(num[i]<'0' || num[i]>'9')
As num[i] is an integer, not a character, checks like this are misleading.
The idea would be to process the input in stages. After the above scanf_s() code succeeds, then you can do this:
Code:
num[i] >= 10 && num[i] <= 100
and it would be sufficient.