Sunday, March 2, 2014

Decision_Structure_If_Statement_Ex01: (Wk-2), Jan 17, 2014

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Decision_Structure_If_Statement_Ex1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Request 2 integer value x and y from user
            //If x > 50 substract 15 from it, otherwise add 30 to it.
            //if y is < 10 add 20 to it, otherwise subtract 10 from  it.
            //Compute sum (x + y) and product (x * y)
            //Display x, y, sum, product


            Console.Write("Enter first integer value: ");
            int x = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter second integer value: ");
            int y = Convert.ToInt32(Console.ReadLine());

            //Check if x is greater than 50
            if (x > 50)
            {
                x = x - 15;
            }
            else
            {
                x = x + 30;
            }

            if (y < 10)
            {
                y = y + 20;
            }
            else
            {
                y = y - 10;
            }
          
            int sum = x + y;
            int prod = x * y;

            Console.WriteLine("\n X = {0} Y = {1}", x, y);
            Console.WriteLine("Sum = {0} Multiplication = {1}", sum, prod);

            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment