So I'm working on a C project which builds a pyramid and I need a little help. The program is to prompt the user for the pyramids height using an integer between 1-8 inclusive. If the users input does not cooperate with the prompt the program will re-prompt the user until they do so. So far I got the program to work however, there's a slit bug. Whenever I type in a non integer the program runs an infinite loop. I just want to program to accept integers. HELP!!
int main(void)
{
int height;
int dashes;
printf("Height Please:\n");
scanf("%d", &height);
while(height<1 || height>8){
printf("Wrong input, try again\n");
scanf("%d", &height);
}
for(int i=1;i<=height;i++)
{
for(dashes=1;dashes<=i;dashes++)
{
printf("#");
}
printf("\n");
}
}