Below is my code in Win Form:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int bx1, bx2, sumbx = 0;
bx1 = int.Parse(txt1.Text);
bx2 = int.Parse(txt1.Text);
sumbx = bx1 + bx2;
txt3.Text = sumbx.ToString();
}
}
The problem is when 2 numbers are added, the result is always less than 1 compared to the actual result. For example: in bx1 I input 1, bx2 I input 2, the expected result must be 3, but it shows 2. Please advise
Thanks,
Ice
Loading
Kirtan PatelPosted Nov 2, 2009, 12:05 PM
you have Logical Error in Your Program Here is Corrected Code
private void button1_Click(object sender, EventArgs e)
{
int bx1, bx2, sumbx = 0;
bx1 = int.Parse(txt1.Text);
bx2 = int.Parse(txt2.Text);
sumbx = bx1 + bx2;
txt3.Text = sumbx.ToString();
}
Now it will Work
check "Do you like this answer" if my answer helped you :)
i would Suggest you to Use Try Parse Instead of Parse Method for better Coding practice :)
Thank you :)
KhoiPosted Nov 2, 2009, 12:08 PM
Thanks a lot
petre ricardoPosted Nov 2, 2009, 12:02 PM
I think this is an eye sight issue (we alway do have... :) )... in your code you are adding the value in textbox tx1 bx1 and bx2..so your problem occurs...
change to this:
petre