DEV Community

Samuel Appiah Kojo
Samuel Appiah Kojo

Posted on

Hi, everyone Let create a basic calculator in C# using Methods Below are some photos. You can check it out!

`
using System;

namespace BasicCalculator
{
class Program
{
static void Main()
{
MathsOperator();
}

   static void MathsOperator()
    {
        string InpOne, InpTwo, ops;
        InpOne = "Please enter your first number";
        InpTwo = "Please enter your second number";
        ops = "Please enter your operator";

        Console.WriteLine("Welcome to my basic Calculator in C#");

        Console.WriteLine(InpOne);
        double num1 = Convert.ToDouble(Console.ReadLine());

        Console.WriteLine(InpTwo);
        double num2 = Convert.ToDouble(Console.ReadLine());

        Console.WriteLine(ops);
        string op = Console.ReadLine();

        if (op == "+")
        {
            Console.WriteLine(num1 + num2);
        }
       else if (op == "-")
        {
            Console.WriteLine(num1 - num2);
        }
       else if (op == "*") 
        {
            Console.WriteLine(num1 * num2);
        }
       else if(op == "/")
        {
            Console.WriteLine(num1 / num2);
        }
        else if (op == "%")
        {
            Console.WriteLine(num1 % num2);
        }
        else
        {
            Console.WriteLine("Invalid operator is found please enter the right operator");
        }
    }

}
Enter fullscreen mode Exit fullscreen mode

}

`

Top comments (0)