Calculator in c# using Method void method
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP_Methods_paractise
{
class Program
{
public void addition(double num1, double num2)
{
double result = num1 + num2;
Console.WriteLine("Addition of Numbers:{0}",result);
}
public void Substruction(double num1, double num2)
{
double result = num1 - num2;
Console.WriteLine("Substruction of Numbers:{0}", result);
}
public void Multiplication(double num1, double num2)
{
double result = num1 * num2;
Console.WriteLine("Multiplication of Numbers:{0}", result);
}
public 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 p1 = new Program();
p1.addition(a,b);
}
else if (op == "-")
{
Program p1 = new Program();
p1.Substruction(a, b);
}
else if (op == "*")
{
Program p1 = new Program();
p1.Multiplication(a, b);
}
else if (op == "/")
{
Program p1 = new Program();
p1.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