Simple Calculator Using Switch Statement in c#.
Simple Calculator Using c#:
output:
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace calculator_using_switch_satement
{
class Program
{
static void Main(string[] args)
{
Console.Write("\tDate Time:");
DateTime dt = DateTime.Now;
Console.WriteLine("{0}",dt);
double a,b,choice,result;
Console.WriteLine("Enter first no");
a = double.Parse(Console.ReadLine());
Console.WriteLine("Enter second no");
b = double.Parse(Console.ReadLine());
Console.WriteLine("----Arithmetical Operaters----");
Console.WriteLine("1.Addition");
Console.WriteLine("2.Substraction");
Console.WriteLine("3.Multiplication");
Console.WriteLine("4.Division");
Console.Write("Which operation you want to choose:");
choice = Convert.ToChar(Console.ReadLine());
switch (choice)
{
case '1':
result = a + b;
Console.WriteLine("Addition of no is:{0}",result);
break;
case '2':
result = a - b;
Console.WriteLine("Substraction of no is:{0}", result);
break;
case '3':
result = a * b;
Console.WriteLine("Multiplication of no is:{0}",result);
break;
case '4':
result = a / b;
Console.WriteLine("Division of no is:{0}", result);
break;
default:
Console.WriteLine("\tInvalid option");
break;
}
}
}
Comments
Post a Comment