Please help!
A program is required that prompts the user for a number between 1 and 20. The prompt should also tell the user “enter 0 to end”. The program will then print a series of asterisks to represent the number. If the user enters 0, the program stops.
Program should print “invalid input” and ask for next input if user enters anything larger than 20 or less than 0.
Did everything except last statement. Can’t do it without interrupting the loop.
Please advice.
Code:
#include<stdio.h>
int main(void)
{
int i=0;
int asterisks;
printf("Enter a number between 1 and 20 ( Enter 0 to end) :");
scanf("%d", &asterisks);
for(i=0; i<asterisks; i++)
printf("%c ", '*');
while(asterisks!=0)
{
printf("\nEnter a number between 1 and 20 ( Enter 0 to end) :");
scanf("%d", &asterisks);
/* if(asterisks>=21 || asterisks<0)
printf("invalid input!"); */
for(i=0; i<asterisks; i++)
printf("%c ", '*');
}
if(asterisks==0)
printf("\nThanks and bye!");
return 0;
}