Computer Science, asked by technicalfriendhelp, 8 months ago

how to create a calculator in c# using if....elseif.....else

Answers

Answered by qiratzahera
0

Hi mate!

is your answer

Answer:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DecisionMaking2

{

   class Program

   {

       static void Main(string[] args)

       {

           Console.WriteLine("Calculator");

           Console.WriteLine("----------------------------");

           Console.WriteLine("1.Add");

           Console.WriteLine("2.Substract");

           Console.WriteLine("3.Multiply");

           Console.WriteLine("4.Divide");

           Console.Write("Enter Choice(1-4):");

           int ch = Int32.Parse(Console.ReadLine());

           int a, b, c;

           if(ch==1)

           {

               Console.Write("Enter A:");

               a = Convert.ToInt32(Console.ReadLine());

               Console.Write("Enter B:");

               b = Convert.ToInt32(Console.ReadLine());

               c = a + b;

               Console.WriteLine("Sum = {0}", c);

           }

           else if(ch==2)

{

               Console.Write("Enter A:");

               a = Convert.ToInt32(Console.ReadLine());

               Console.Write("Enter B:");

               b = Convert.ToInt32(Console.ReadLine());

               c = a - b;

               Console.WriteLine("Difference = {0}", c);

           }

           else if(ch==3)

           {

               Console.Write("Enter A:");

               a = Convert.ToInt32(Console.ReadLine());

               Console.Write("Enter B:");

               b = Convert.ToInt32(Console.ReadLine());

               c = a * b;

               Console.WriteLine("Product = {0}", c);

           }

           else if(ch==4)

           {

               Console.Write("Enter A:");

               a = Convert.ToInt32(Console.ReadLine());

               Console.Write("Enter B:");

               b = Convert.ToInt32(Console.ReadLine());

               c = a / b;

               Console.WriteLine("Quotient = {0}", c);

           }

else

           {

               Console.WriteLine("Invalid Choice");

           }

           Console.ReadKey();

       }

   }

}

Similar questions