if1.c

  #include <stdio.h>

  int main()
  {
     int age;
     printf("Acme movie theatre\n");
     printf("Input your age: ");
     scanf("%d", &age);
     if (age < 21)
     {
         printf("You are too young to watch this movie.\n");
     }
     return 0;
  }
  • Try to run this program.
  • When you input the age with the number of less than 21, what happened? You get the message: "You're too young to watch this movie."
  • If you input the age with 21 or more, then nothing gets printed. Why? Because the condition age < 21 is not satisfied, and thus the computer skip the commands within the braces.

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001