Amit wants to develop an arithmetic calculator to perform some arithmetic functions. Develop a program to achieve the same
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1 - Addition");
Console.WriteLine("2 - Subtraction");
Console.WriteLine("3 - Multiplication");
Console.WriteLine("4 - Division");
Console.Write("Select the action: ");
int action = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 1: ");
float number1 = float.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
float number2 = float.Parse(Console.ReadLine());
float result = 0;
switch (action)
{
case 1:
{
result = Addition(number1, number2);
break;
}
case 2:
{
result = Subtraction(number1, number2);
break;
}
case 3:
{
result = Multiplication(number1, number2);
break;
}
case 4:
{
result = Division(number1, number2);
break;
}
default:
Console.WriteLine("Wrong action!! try again");
break;
}
Console.WriteLine("The result is {0}", result);
Console.ReadKey();
}
//Addition
public static float Addition(float number1, float number2)
{
return number1 + number2;
}
//Substraction
public static float Subtraction(float number1, float number2)
{
return number1 - number2;
}
//Multiplication
public static float Multiplication(float number1, float number2)
{
return number1 * number2;
}
//Division
public static float Division(float number1, float number2)
{
return number1 / number2;
}
}
}
Comments
Leave a comment