Description
Using basic expressions, calculate a person’s age given their birth year and the current year.
Requirements
- Prompt the user to enter an integer. This number will represent a person’s birth year.
- Prompt the user to enter an integer. This number will represent the current year.
- 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
using System; namespace EXP0001 { class Program { static void Main(string[] args) { int birth, now; Console.Write("Enter the person's birth year: "); int.TryParse(Console.ReadLine(), out birth); Console.Write("What is the current year: "); int.TryParse(Console.ReadLine(), out now); Console.WriteLine("You are {0} years old", now - birth); Console.ReadKey(); } } }
CATALOG ID: CS-EXP0001
Print Requirements