Limiting input to only positive integers?
I'm writing the Mario half pyramid and I'm using user input to create a pyramid of the height (user input). However, I forgot to limit it to only positive integers (1-23) and not non integers or just pressing "enter". Any ideas on how I can go about doing this?
Code:
#include <stdio.h>
int main(int argc, const char *argv[])
{
int height = 0;
int i=0,j=0,k=0;
do
{
printf("Height: ");
scanf("%d", &height);
}
while (height < 0 || height > 23);
int spacing=height-1;
int hash=2;
for (i=0; i<height; i++)
{
for (j=spacing; j>0; j--)
{
printf(" ");
}
for (k=0; k<hash; k++)
{
printf("#");
}
spacing--;
hash++;
printf("\n");
}
return 0;
}