Calculator in c# using Static Methods
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP_Methods_paractise
{
class Program
{
public static void addition(double num1, double num2)
{
double result = num1 + num2;
Console.WriteLine("Addition of Numbers:{0}",result);
}
public static void Substruction(double num1, double num2)
{
double result = num1 - num2;
Console.WriteLine("Substruction of Numbers:{0}", result);
}
public static void Multiplication(double num1, double num2)
{
double result = num1 * num2;
Console.WriteLine("Multiplication of Numbers:{0}", result);
}
public static void Division(double num1, double num2)
{
double result = num1 / num2;
Console.WriteLine("Division of Numbers:{0}", result);
}
static void Main(string[] args)
{
string ans;
do
{
Console.WriteLine("Enter First Number:");
double a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Second Number:");
double b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Operator do you want to perform(+,-,*,/)");
string op = Convert.ToString(Console.ReadLine());
if (op == "+")
{
Program.addition(a, b);
}
else if (op == "-")
{
Program.Substruction(a, b);
}
else if (op == "*")
{
Program.Multiplication(a, b);
}
else if (op == "/")
{
Program.Division(a, b);
}
else
{
Console.WriteLine("Invalid Operation");
}
Console.WriteLine("Do you want to Perform More Operations(yes,no)");
ans = Console.ReadLine().ToLower();
} while (ans == "yes");
}
}
}
Comments
Post a Comment