How to make calculator in c# in 5 minutes

How to make calculator in c# in 5 minutes



Write a program which allows any user to perform addition, subtraction, multiplication or division on two numbers entered. And the program generates an error message in case of invalid input of quantity or an operator. 




Code


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace Calculator

{

    class Program

   

        static void Main(string[] args)

        {

            int num, num1, num2;

            float num3, num4, Result1;

            int Result;



            Console.WriteLine("\t\t*******welcome Tlo The Calculator********\n");

            Console.WriteLine("\t\t*******Enter The Number What You Want\n");

            Console.WriteLine("1..........For Additon");

            Console.WriteLine("2..........For Subtraction");

            Console.WriteLine("3..........For Division");

            Console.WriteLine("4..........Multiplication");



            num = int.Parse(Console.ReadLine());

            switch (num)

            {

                case 1:

                    {

                        Console.WriteLine("1..........For Additon\n");

                        Console.WriteLine("Enetr The First  Number");

                         num1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Enetr The second  Number");

                         num2 = int.Parse(Console.ReadLine());

                         Result = (num1 + num2);

                         Console.WriteLine("Result is  :  "+Result);

                       

                        break;

                    }



                case 2:

                    {



                        Console.WriteLine("2..........For Subtraction\n");

                        Console.WriteLine("Enetr The First  Number");

                         num1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Enetr The second  Number");

                         num2 = int.Parse(Console.ReadLine());

                         Result = num1 - num2;

                         Console.WriteLine("Result is  :  " + Result);

                        break;

                    }



                    Console.WriteLine("3..........For Division\n");

                        Console.WriteLine("Enetr The First  Number");

                         num3 = float.Parse(Console.ReadLine());

                        Console.WriteLine("Enetr The second  Number");

                         num4 = float.Parse(Console.ReadLine());

                         Result1 =  num3 /num4;

                         Console.WriteLine("Result is  :  " + Result1);

                        break;

                    }



                case 4:

                    {

                        Console.WriteLine("4..........Multiplication\n");

                        Console.WriteLine("Enetr The First  Number");

                         num1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Enetr The second  Number");

                         num2 = int.Parse(Console.ReadLine());

                         Result = num1 * num2;

                         Console.WriteLine("Result is  :  " + Result);

                        break;

                    }

                default :

                    {

                        Console.WriteLine("\t\tInvalid Input ");

                    }

                    break;



            }

        }

    }

 





Popular posts from this blog

Real marksheet using HTML

Salary Calculate Application in C#