Thursday, 15 October 2015

Addition Substraction Multiplication and Division using Switch Statement

using System;
class Program
{
    public static void Main()
    {
        double result=0;
        Console.WriteLine("Enter First Number");
        double FN=double.Parse(Console.ReadLine());
        Console.WriteLine("Enter Second Number");
        double SN = double.Parse(Console.ReadLine());

        Console.WriteLine("Choose which action you wanna perform");
        Console.WriteLine("Press 1 for Addition");
        Console.WriteLine("Press 2 for Substraction");
        Console.WriteLine("Press 3 for Multiplication");
        Console.WriteLine("Press 4 for Division");
        int userChoice = int.Parse(Console.ReadLine());

        switch (userChoice)
        {
            case 1:
                result = FN + SN;
                break;
            case 2:
                result = FN - SN;
                break;
            case 3:
                result = FN * SN;
                break;
            case 4:
                result = FN / SN;
                break;
            default:
                Console.WriteLine("You entered invalid number. Please try again...");
                break;
        }
        Console.WriteLine("Result is = {0}",result);
    }
}

No comments:

Post a Comment