Control structure: if / else

A restaurant gives a discount to children AND seniors. When we write the program, we test if someone is a child OR a senior. One person can't be both a child and a senior.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Children and Seniors get discount
#include <iostream>
using namespace std;
int main() { 
  int age;
  cout<<"Enter your age:";
  cin>>age;
  if (age <=12 || age>=65)
     cout<<"You get a discount\n";
  else
     cout<<"You do not get a discount\n";
  system("pause");
  return 0;
} // main
CODE

When you write a program like this, it is important to clarify exactly what is meant by "child" and "senior." In this example 12 is considered a child and 65 is considered a senior.

Good test data would include age<12, age==12, age between 13 and 64, age==65, and age>65.

Challenge: Try writing this to test for who doesn't get a discount in the if statement.

NEXT: Print season based on month