CSharp - Write program to Do Calculation with Entered Number

Requirements

You will do calculation with the value entered by the user.

You will write a program that accepts a year of birth from the user and calculates the age afterward.

Hint

Prompt user with a message, let user input the year of birth.

Convert the user input to int type value.

Create DateTime value from today's date and then get current year value.

Use subtract to get the difference

Demo

using System;
class Program{/*from w  w w  .  j  a  v a  2s  . c  o m*/
    static void Main(string[] args){
        // Prompting the user 
        Console.Write("Enter year of your birth: ");

        // Reading line of text 
        string input = Console.ReadLine();

        // CONVERING TO NUMBER (of entered text) 
        int yearOfBirth = Convert.ToInt32(input);

        // Finding this year 
        DateTime today = DateTime.Today;
        int thisYear = today.Year;

        // Calculating age 
        int age = thisYear - yearOfBirth;

        // Outputting the result 
        Console.WriteLine("This year you are/will be: " + age);

    }
}

Result