C# Tutorial While Loops with Loan Calculator tryparse try and catch

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 5

  • @shwetachavan751
    @shwetachavan751 8 месяцев назад

    Thank you so much for the tutorial. It's easy to understand and very informative

  • @mikepowertech2679
    @mikepowertech2679 3 года назад

    Dear professor Shad, thank you for the great tutorial.

  • @fes4471
    @fes4471 4 года назад +1

    hey,
    I tried to do it with try parse and try catch.
    For some reason my programm doesnt work.
    The result is 600 at the first month, 3600 at the second month. (loan_amount 100, number of months 10, interestrate: 0.005)
    I didn't forget the "m" for the decimal variable.
    Does Anyone have a solution?
    I can send a printscreen from my code with lightshot if it doesnt get blocked.
    edit:
    In the listbox my result also doesnt have a "." ( I mean this comma)
    public partial class Form1 : Form
    {
    decimal loan_amount = 0.00m;
    int number_of_months = 0;
    decimal interest_rate = 0.005m;
    public Form1()
    {
    InitializeComponent();
    }
    private void label1_Click(object sender, EventArgs e)
    {
    }
    private void label2_Click(object sender, EventArgs e)
    {
    }
    private void btn_Calculate_Click(object sender, EventArgs e)
    {
    if ( decimal.TryParse(txt_loanAmount.Text, out loan_amount))
    {
    if ( int.TryParse(txt_NumberOfMonths.Text, out number_of_months))
    {
    if (decimal.TryParse(txt_InterestRate.Text, out interest_rate))
    {
    int counter = 0;
    while (counter < number_of_months)
    {
    loan_amount = loan_amount + loan_amount * interest_rate;
    listBox1.Items.Add(loan_amount);
    counter = counter + 1;
    }
    }
    }
    }

    }
    }

    • @fes4471
      @fes4471 4 года назад

      Solution:
      using System.Globalization;
      decimal.TryParse(txt_interestrate.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out interest_rate));

  • @2005Azm
    @2005Azm 4 года назад

    Thanks for sharing