private void btnCalculate_Click(object sender, EventArgs e)
        {
            Serial = 0;
            Converter     converter     = new Converter();
            int           TotalYear     = Convert.ToInt32(tbTotalYear.Text.Trim());
            CalcInterests calcInterests = new CalcInterests();

            double principlePerYear = converter.ToDouble(tbPrincipal.Text.Trim());
            double principaltotal   = 0;
            double TimesPerYear     = converter.ToDouble(tbTimesInYear.Text.Trim());
            //double smallYear = converter.ToDouble(tbYear.Text.Trim()) / TimesPerYear;
            double bigYear    = converter.ToDouble(tbTotalYear.Text.Trim()) * TimesPerYear;
            double monthToPay = converter.ToDouble(tbYear.Text.Trim()) / 12 * TimesPerYear;

            for (int i = 0; i < bigYear; i++)
            {
                principaltotal = principaltotal + principlePerYear;
                Interest       = calcInterests.CalculateCompoundInterest(principaltotal.ToString(), "0", monthToPay.ToString(), tbRate.Text.Trim().ToString(), tbNoOfTimes.Text.Trim().ToString());
                principaltotal = +CalculateCompoundInterest(principaltotal, Interest, TimesPerYear);
            }
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            Converter converter = new Converter();

            try
            {
                CalcInterests calcInterests = new CalcInterests();
                Interest  = calcInterests.CalculateCompoundInterest(tbPrincipal.Text.Trim().ToString(), tbYear.Text.Trim().ToString(), tbMonth.Text.Trim().ToString(), tbRate.Text.Trim().ToString(), tbNoOfTimes.Text.Trim().ToString());
                Principal = converter.ToDouble(tbPrincipal.Text.Trim().ToString());
                Rate      = converter.ToDouble(tbRate.Text.Trim().ToString());
                Time      = converter.ToDouble(tbYear.Text.Trim().ToString()) * 12 + converter.ToDouble(tbMonth.Text.Trim().ToString());
                Interest  = Interest - Principal;
                Interestdata interestdata2 = new Interestdata();
                interestdata           = interestdata2;
                interestdata.Interest  = Interest;
                interestdata.Total     = Interest + Principal;
                interestdata.Principal = Principal;
                interestdata.Rate      = Rate;

                interestdata.Time_Month = Time;;
                if (interestDatalist == null)
                {
                    List <Interestdata> list = new List <Interestdata>();
                    interestDatalist = list;
                }
                interestDatalist.Add(interestdata);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = interestDatalist;
                Label lb = new Label();
                lb.Location = new Point(251, 70);
                lb.Text     = Interest.ToString();

                // Adding this label in the form
                this.Controls.Add(lb);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public double CalculateCompoundInterest(double p = 0, double i = 0, double timesInYear = 0)
        {
            Converter converter = new Converter();

            try
            {
                if (p == 0)
                {
                    Principal = converter.ToDouble(tbPrincipal.Text.Trim().ToString());
                }
                else
                {
                    Principal = p;
                }
                CalcInterests calcInterests = new CalcInterests();
                if (i == 0)
                {
                    Interest = calcInterests.CalculateCompoundInterest(Principal.ToString(), tbYear.Text.Trim().ToString(), tbMonth.Text.Trim().ToString(), tbRate.Text.Trim().ToString(), tbNoOfTimes.Text.Trim().ToString());
                }
                else
                {
                    Interest = i;
                }

                Rate     = converter.ToDouble(tbRate.Text.Trim().ToString());
                Time     = converter.ToDouble(tbYear.Text.Trim().ToString()) * 12 + converter.ToDouble(tbMonth.Text.Trim().ToString());
                Interest = Interest - Principal;
                Interestdata interestdata2 = new Interestdata();
                interestdata           = interestdata2;
                interestdata.Interest  = Interest;
                interestdata.SN        = Serial;
                interestdata.Total     = Interest + Principal;
                interestdata.Principal = Principal;
                interestdata.Rate      = Rate;
                if (timesInYear == 0)
                {
                    interestdata.Time_Month = Time;;
                }
                else
                {
                    interestdata.Time_Month = timesInYear;
                }
                if (interestDatalist == null)
                {
                    List <Interestdata> list = new List <Interestdata>();
                    interestDatalist = list;
                }
                interestDatalist.Add(interestdata);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = interestDatalist;
                Label lb = new Label();
                lb.Location = new Point(251, 70);
                lb.Text     = Interest.ToString();

                // Adding this label in the form
                this.Controls.Add(lb);
                return(interestdata.Total);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(interestdata.Total);
        }