Hi,
I am having trouble writing the code to work for my C# .Net assignment.
I already design the form and now I have to get the code to work for my program. The problem I am having is if I put a number in my design form other than (1) the factorial comes back as (1.00000000000). I am not getting the correct answer. Here is my code:
private void btnCalculae_Click(object sender, System.EventArgs e)
{
long number = Convert.ToInt64 (txtNumber.Text);
long factorial = 1;
lblFactorial.Text = factorial.ToString("n20");
// calculate factorial
while ( number > 0 && number <= 20)
{
factorial *= number;
number++;
} // end while loop
txtNumber.Text = "";
txtNumber.Focus();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
What am I doing wrong!!!!!!!! Please help