Program that ensures age values are reasonable with if statement - C++ Statement

C++ examples for Statement:if

Description

Program that ensures age values are reasonable with if statement

Demo Code

#include <stdio.h>
int main()/*from www  . ja  v a  2s  . c  o  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;
}

Result


Related Tutorials