Thursday, August 12, 2010

program to calculate total interest based on given conditions using if condition.


Write a program to calculate total interest based on given conditions using if condition.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Csharp
{
    
    /// <summary>
    /// Calculating Total interest based on the given conditions:
    /// Principle Amount     Rate of Interest
    /// >=10,000                20%
    /// >=8000&&<=9999          18%
    /// <8000                   16%
    /// </summary>
    class IFCondition
    {
        public float princ, nyrs, rate, interest;
        public static void Main(string[] args)
        {
            IFCondition obj = new IFCondition();
            obj.res();
            Console.ReadLine();
        }


        public void res()
        {
            Console.Write("\n Enter Loan and No of Years");
            princ = Convert.ToInt32(Console.ReadLine());
            nyrs = Convert.ToInt32(Console.ReadLine());
            if (princ >= 10000)
            {
                rate = 20;
            }
            else if (princ >= 8000 && princ <= 9999)
            {
                rate = 18;
            }
            else if (princ < 8000)
            {
                rate = 16;
            }
            interest = princ * nyrs * rate / 100;
            Console.Write("Years:{0}", nyrs);
            Console.Write("Loan:{0}", princ);
            Console.Write("Rate of Interest:{0}", rate);
            Console.Write("Interest Amount:{0}", interest);
        }
    }
}

No comments:

Post a Comment