Reputation: 1
I am new to programing and am trying to make a simple calculator but using radio buttons for the + - * / buttons. The form has two text boxes for the user with the radio buttons in between and a text box for the answer to go into. What is wrong with this code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int itextBox1 = 0;
int itextBox2 = 0;
int itextBox3 = 0;
itextBox1 = Convert.ToInt32(textBox1.Text);
itextBox2 = Convert.ToInt32(textBox2.Text);
if (radioButton1.Checked)
{
itextBox3 = itextBox1 + itextBox2;
}
else if (radioButton2.Checked)
{
itextBox3 = itextBox1 - itextBox2;
}
else if (radioButton3.Checked)
{
itextBox3 = itextBox1 * itextBox2;
}
else if (radioButton4.Checked)
{
itextBox3 = itextBox1 / itextBox2;
}
}//void
}//class
Upvotes: 0
Views: 114
Reputation: 4652
you can just add
MessageBox.Show(itextBox3.ToString());
to show your result
private void button1_Click(object sender, EventArgs e)
{
int itextBox1 = 0;
int itextBox2 = 0;
int itextBox3 = 0;
itextBox1 = Convert.ToInt32(textBox1.Text);
itextBox2 = Convert.ToInt32(textBox2.Text);
if (radioButton1.Checked)
{
itextBox3 = itextBox1 + itextBox2;
}
else if (radioButton2.Checked)
{
itextBox3 = itextBox1 - itextBox2;
}
else if (radioButton3.Checked)
{
itextBox3 = itextBox1 * itextBox2;
}
else if (radioButton4.Checked)
{
itextBox3 = itextBox1 / itextBox2;
}
MessageBox.Show(itextBox3.ToString());
}
Upvotes: 2
Reputation: 26219
Problem : You are not displaying the result value on TextBox3.
Try This:
itextBox3.Text=itextBox3.ToString();
Upvotes: 3
Reputation: 16338
You probably need to add this:
textBox3.Text = itextBox3.ToString();
Did you debug your code? What are the problems.
What is the point of empty event handlers?
Upvotes: 3
Reputation: 152654
You're calculating a result but not doing anything with it. Add something like
textBox3.Text = itextBox3.ToString();
after your calculations.
Upvotes: 3