Calculation with entered number - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Calculation with entered number

Demo Code

using System;/*ww w.  jav a 2s  . co m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    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);
        // Number input
        Console.Write("Enter a number: ");
         input = Console.ReadLine();
        int number = Convert.ToInt32(input);
        // Calculating
        int result = number + 10;
        // Displaying the result
        Console.WriteLine("Number greater by ten: " + result);
    }
}

Result


Related Tutorials