Im new to C, and today I encountered a problem I haven't managed to figure out, so I need some help. We've been given this task:
'Write a program that demonstrates a ‘while’ loop that uses the ‘read-ahead’ technique: it asks the user to enter numbers between (and including) 10 and 100, entering a zero terminates the loop. If numbers less than 10 or larger than 100 are entered an error message is shown (e.g. “Error: 250 is not allowed”). After termination of the loop the program prints the amount of numbers that was entered.'
The issue I have is that once I type in a valid number (between 10-100) the program sits still, it doesn't terminate nor loop. On the other hand, if I type in a non valid number like 8, 102 it loops the printf("Error, %d is not allowed\n", num);
here's the code:
#include <stdio.h>
main(void)
{
int num;
int counter=1;
printf("Please type in your number between (and including) 10-100\n");
scanf("%d", &num);
if((num <10) || (num >100))
{
printf("Error, %d is not allowed\n", num);
}
while (num > 0)
{
counter++;
if((num <10) || (num >100))
{
printf("Error, %d is not allowed\n", num);
}
counter++;
}
printf("%d numbers were entered!\n", counter);
}