Simple Expressions 3

Description

Using basic expressions, calculate a person’s age given their birth year and the current year.

Requirements

  1. Prompt the user to enter an integer. This number will represent a person’s birth year.
  2. Prompt the user to enter an integer. This number will represent the current year.
  3. Display a message to the user showing the person’s age.

Sample Interaction / Output

Enter the person's birth year: 1990
What is the current year: 2000
You are 10 years old.

LEGEND
PROGRAM OUTPUT
USER ENTRY 

Solution

#include <iostream>

using namespace std;

int main()
{
  int birth, now;

  cout << "Enter the person's birth year: ";
  cin >> birth;
  cout << "What is the current year: ";
  cin >> now;
  cout << "You are " << now - birth << " years old.";

  return 0;
}

CATALOG ID: CPP-EXP0003

Print Requirements