You are on page 1of 2

Calculator with Switch_Case

namespace CALCULATOR_WITH_SWITCH
{
class Program
{
static void Main(string[] args)
{
int n1, n2, opr, result;
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("SIMPLE CALCULATOR");
Console.WriteLine("\nFirst Number");
n1 = int.Parse(Console.ReadLine());
Console.WriteLine("\nSecond Number");
n2 = int.Parse(Console.ReadLine());

Console.WriteLine(@"Operations are:
1. Addition
2. Subtraction
3. Multiplication
4. Division");

opr = int.Parse(Console.ReadLine());
switch (opr)
{
case 1:
result = n1 + n2;
Console.WriteLine("\n Sum of {0} and {1} is {2}", n1, n2, result);
break;
case 2:
result = n1 - n2;
Console.WriteLine("\n Subtraction of {0} and {1} is {2}", n1, n2, result);
break;
case 3:
result = n1 * n2;
Console.WriteLine("\n Product of {0} and {1} is {2}", n1, n2, result);
break;
case 4:
result = n1 / n2;
Console.WriteLine("\n Division of {0} and {1} is {2}", n1, n2, result);
break;
default:
break;
}

Console.ReadLine();

}
}
}

You might also like