Friday, October 20, 2017

Calculator in C#

In this article I would like to share with you a simple program that uses methods in C# I called this program calculator in C# what does the program will do is to ask the user to give two values and then it will compute the sum, product, difference and quotient of the given two numbers from our user.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.



Program Listing

calculator.cs


class calculator
    {
        double  sum(double n1, double  n2)
        {
            return n1 + n2;
        }
        double  subtract(double n1, double  n2)
        {
            return n1 - n2;
        }
        double multiply(double  n1, double n2)
        {
            return n1 * n2;
        }
        double division(double  n1, double n2)
        {
            return n1 / n2;
        }
        static void Main(string[] args)
        {
            calculator c = new calculator();
            double input1, input2;
    
       Console.WriteLine("Calculator in C#");
Console.Write("\n\n");
            Console.WriteLine("Give first value : ");
            input1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Give second value : ");
            input2 = Convert.ToDouble(Console.ReadLine());
            double x = c.sum(input1, input2);
            double y = c.multiply(input1, input2);
            double z = c.division(input1, input2);
            double w = c.subtract(input1, input2);

               Console.WriteLine("subtraction {0}",w);
               Console.WriteLine("sum {0}", x);
               Console.WriteLine("multiply {0}", y);
               Console.WriteLine("division {0}", z);
   
Console.Write("\n\n");
               Console.Write("Thank You For Using This Software.");
               Console.Write("\n\n");
        }   
    }
}


No comments:

Post a Comment