C++ if statement ensures age values are reasonable

Description

C++ if statement ensures age values are reasonable

#include <stdio.h>
int main()/*w  ww.  j av a 2 s  . co  m*/
{
   int age;
   printf("\nWhat is the student's age? ");
   scanf(" %d", &age);  // With scanf(), remember the &
   if (age < 10)
   {
      printf("%c", '\x07');   // BEEP
      printf("*** The age cannot be less than 10 ***\n");
      printf("Try again...\n\n");
      printf("What is the student's age? ");
      scanf(" %d", &age);
   }
   printf("Thank you. You entered a valid age.");
   return 0;
}



PreviousNext

Related