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; } } } }
Thank you so much for the tutorial. It's easy to understand and very informative
Dear professor Shad, thank you for the great tutorial.
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;
}
}
}
}
}
}
Solution:
using System.Globalization;
decimal.TryParse(txt_interestrate.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out interest_rate));
Thanks for sharing