• Language

    C#

  • Description

    It performs arithmetic operations like sum, product, difference, and quotient.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;

namespace SumProductDifferenceAndQuotient
{
    class SumProductDifferenceAndQuotient
    {
        static void Main(string[] args)
        {
            int operation;
            double a, b, result;
            Console.Write("Enter the value of a: ");
            a = double.Parse(Console.ReadLine());
            Console.Write("Enter the value of b: ");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("Select the value of operation.");
            Console.WriteLine("\t1.- sum");
            Console.WriteLine("\t2.- product");
            Console.WriteLine("\t3.- difference");
            Console.WriteLine("\t4.- quotient");
            Console.Write("\t: ");
            do
            {
                operation = int.Parse(Console.ReadLine());
                if (operation<1||operation>4)
                    Console.Write("Wrong value. Please, enter it again.: ");
            } while (operation<1||operation>4);
            result=0;
            if(operation==1)
                result=a*b;
            if(operation==2)
                result=a-b;
            if(operation==3)
                result=a-b;
            if(operation==4&&b!=0)
                result=a/b;
            if(operation==4&&b==0)
                Console.WriteLine("Indetermination");
            Console.WriteLine("Value of result: " + result);
            Console.WriteLine();
            Console.Write("Press any key to finish . . . ");
            Console.ReadKey();
        }
    }
}