Ensure user to type in the number in range with while loop - C Statement

C examples for Statement:while

Description

Ensure user to type in the number in range with while loop

Demo Code

#include <stdio.h>
int main()/*w  w  w.  jav  a  2  s . co  m*/
{
   int start;
   long delay;
   do
   {
      printf("Please enter the number to start\n");
      printf("the countdown (1 to 100):");
      scanf("%d",&start);
   }
   while(start<1 || start>100);
   /* The countdown loop */
   do
   {
      printf("T-minus %d\n",start);
      start--;
      for(delay=0;delay<100000;delay++);   /* delay loop */
   }
while(start>0);
printf("Zero!\nBlast off!\n");
return(0);
}

Result


Related Tutorials