0

Hello I am doing calculation using comboxBox...But it is not doing correctly

a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            if (comboBox1.Text == "*")
            {
                c = a * b;
            }
            textBox3.Text = c.ToString();

Any help here can point out where problem is ?

Thanks

2
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by ddanbe
0

Sorry, but I can't open your image.:(
it's perhaps better to upload it or else to just explain what is happening.

0

The int.Parse method tries to translate the text of the textbox into an integer. If the textbox contains nothing else but numbers it will be OK. If you type e.g. your name into the textbox, you will get this error.

0

if i remove int.Parse

it says " Cannot implicitly convert type 'string' to 'int' "

Thanks

1

If you also want to do calculations with a decimal point, you have to change the type of your variables a, b and c into float or double, instead of int.

Votes + Comments
picked up on both possible causes of the error :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.