It is saying that input string was not in correct format, the line thats bold is the problem? Please tell me whats wrong with it, and how to fix it, thanks in advance.
{
double a;
double b;
double c;
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = Math.Sqrt((a * a) + (b * b));
label1.Text = c.ToString();
}
Loading

Santhosh NRank #4,788 · 325 reputationPosted Jan 27, 2010, 8:10 PM EST
You can only parse values which are parsable but not anything you give...
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Jan 27, 2010, 9:00 PM EST
Change your code as follows.
double a;
double b;
double c;
if((double.TryParse(textBox1.Text, a)) && (double.TryParse(textBox2.Text, b))
{
c = Math.Sqrt((a * a) + (b * b));
label1.Text = c.ToString();
}
else
MessageBox.Show("You have entered an invalid input.");
If you find my answer useful, please tick 'Do you like this answer' checkbox.
ashish Jadhav4 reputationPosted Jan 27, 2010, 10:24 PM EST
This will surely work...
double a;
double b;
double c;
a =Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);
c = Math.Sqrt((a * a) + (b * b));
label1.Text = c.ToString();