T
Tony Jo
I was wondering why the following code causes an infinite loop when i type
in an alphabetic character?
while (bool == 0)
{
if(scanf("%d", &subjectDuration) == 1)
{
if(subjectDuration > 26 || subjectDuration < 0)
{
printf("The number of weeks is invalid,");
printf("please try again.\n");
}
else
bool = 1;
}
else
{
printf("You have entered an invalid character,");
printf("please try again.\n");
}
}
in an alphabetic character?
while (bool == 0)
{
if(scanf("%d", &subjectDuration) == 1)
{
if(subjectDuration > 26 || subjectDuration < 0)
{
printf("The number of weeks is invalid,");
printf("please try again.\n");
}
else
bool = 1;
}
else
{
printf("You have entered an invalid character,");
printf("please try again.\n");
}
}