Tuesday, 17 September 2013

Console Application : Addition , Subtraction , Division , Multiplication Using Switch Cases.

Create New Console Application Program Name It Operation Console.
Change Your Program.cs Code With Following Code.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OperationConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            int Number1, Number2;
            char option;
            int Result;
            Console.WriteLine("Enter the First Number:"); 
            Number1 = Convert.ToInt32(Console.ReadLine()); 
 
            Console.WriteLine("Enter the Second Number:"); 
            Number2 = Convert.ToInt32(Console.ReadLine()); 
 
            Console.WriteLine("Main Menu"); 
            Console.WriteLine("1. Addition"); 
            Console.WriteLine("2. Subtraction"); 
            Console.WriteLine("3. Multiplication"); 
            Console.WriteLine("4. Division"); 
 
            Console.WriteLine("Enter the Operation Number To Perform Operation"); 
            option = Convert.ToChar(Console.ReadLine()); 
 
            switch (option) 
            { 
                case '1': 
                    Result = Number1 + Number2; 
                    Console.WriteLine("Addition is:{0}", Result); 
                    break; 
                case '2': 
                    Result = Number1 - Number2; 
                    Console.WriteLine("Subtraction is:{0}", Result); 
                    break; 
                case '3': 
                    Result = Number1 * Number2; 
                    Console.WriteLine("Multiplication is:{0}", Result); 
                    break; 
                case '4': 
                    Result = Number1 / Number2; 
                    Console.WriteLine("Division is:{0}", Result); 
                    break; 
                default: 
                    Console.WriteLine("Invalid Option"); 
                    break; 
            } 
            Console.ReadLine(); 
        } 
        }
    }


First Enter Two Numbers Respectively . Then Enter Operation Number To Perform Then Press Enter.

Output Will Be Like Below.


















All The Best :)

No comments:

Post a Comment