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 ?


Recommended Answers

All 8 Replies

Could you tell exactly what is not working?
Your code works fine when I use it.

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

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.

if i remove int.Parse

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


it worked now
Thanks for help

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.

commented: picked up on both possible causes of the error :) +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.