problem in simple calculation
-
hi i am new to c# programming and i am getting problem in asp.net i am trying to make simple division in two fields and get their result in the thired textbox on a button click. this is my code void Button2_Click(object sender, EventArgs e) { int val = int.Parse(tb1.Text); lbl1.Text = val.ToString(); int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); int c = int.Parse(your_amount.Text); your_amount.Text = c.ToString(a/b); } Total Fee:
Course Length:
Your balance: Mazhar Hussain
-
hi i am new to c# programming and i am getting problem in asp.net i am trying to make simple division in two fields and get their result in the thired textbox on a button click. this is my code void Button2_Click(object sender, EventArgs e) { int val = int.Parse(tb1.Text); lbl1.Text = val.ToString(); int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); int c = int.Parse(your_amount.Text); your_amount.Text = c.ToString(a/b); } Total Fee:
Course Length:
Your balance: Mazhar Hussain
If you are attempting to divide a by b and supply it to the your_amount textbox, then use the following code (your code modified).... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = (string)(a/b); If you want to make sure your code accomodates when c_length is zero, then use the following code... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = b==0 ? 0 : (string)(a/b); Ryan Bost http://www.sugarcoding.com
-
If you are attempting to divide a by b and supply it to the your_amount textbox, then use the following code (your code modified).... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = (string)(a/b); If you want to make sure your code accomodates when c_length is zero, then use the following code... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = b==0 ? 0 : (string)(a/b); Ryan Bost http://www.sugarcoding.com
Hi Ryan you modify my code but it is not working ... it is giving me the same error that Compiler Error Message: CS0030: Cannot convert type 'int' to 'string' on this line your_amount.Text = (string)(a/b); any other brights ideas ... me waiting ... Mazhar Hussain
-
Hi Ryan you modify my code but it is not working ... it is giving me the same error that Compiler Error Message: CS0030: Cannot convert type 'int' to 'string' on this line your_amount.Text = (string)(a/b); any other brights ideas ... me waiting ... Mazhar Hussain
Sorry Mazhar... ...try this instead... your_amount.Text = (a/b).ToString(); Ryan Bost http://www.sugarcoding.com
-
Sorry Mazhar... ...try this instead... your_amount.Text = (a/b).ToString(); Ryan Bost http://www.sugarcoding.com