I'm confused on how to get this program to do a few certain things and a question for future reference for myself:
Question: Can you do if statements with buttons example: if (button1 is clicked) do this else if (button2 is clicked) do this
The goal of my program is to help learn basic integer mathematics and the four sections are ADDING, SUBTRACTING, MULTIPLYING, and MOD. I have four buttons for each one of those topics, and a fifth button to submit the answer for the question, I have 3 text boxes, the first being the question that is presented, second being the users answer, third being whether the answer was correct or not
What I currently have set up:
private void button1_Click(object sender, EventArgs e)
{
Random random1 = new Random();
int randomNumber1 = random1.Next(6, 11);
Random random2 = new Random();
int randomNumber2 = random2.Next(1, 6);
textBox1.Text = "What is " + randomNumber1 + " + " + randomNumber2 + " ?";
}
private void button2_Click(object sender, EventArgs e)
{
Random random1 = new Random();
int randomNumber1 = random1.Next(6, 11);
Random random2 = new Random();
int randomNumber2 = random2.Next(1, 6);
textBox1.Text = "What is " + randomNumber1 + " - " + randomNumber2 + " ?";
}
private void button3_Click(object sender, EventArgs e)
{
Random random1 = new Random();
int randomNumber1 = random1.Next(6, 11);
Random random2 = new Random();
int randomNumber2 = random2.Next(1, 6);
textBox1.Text = "What is " + randomNumber1 + " * " + randomNumber2 + " ?";
}
private void button4_Click(object sender, EventArgs e)
{
Random random1 = new Random();
int randomNumber1 = random1.Next(6, 11);
Random random2 = new Random();
int randomNumber2 = random2.Next(1, 6);
textBox1.Text = "What is " + randomNumber1 + " % " + randomNumber2 + " ?";
}
private void button5_Click(object sender, EventArgs e)
{
Random random1 = new Random();
int randomNumber1 = random1.Next(6, 11);
Random random2 = new Random();
int randomNumber2 = random2.Next(1, 6);
if (Convert.ToInt16(textBox2.Text) == (randomNumber1) + (randomNumber2))
textBox3.Text = "Correct!";
else if (Convert.ToInt16(textBox2.Text) == (randomNumber1) - (randomNumber2))
textBox3.Text = "Correct!";
else if (Convert.ToInt16(textBox2.Text) == (randomNumber1) * (randomNumber2))
textBox3.Text = "Correct!";
else if (Convert.ToInt16(textBox2.Text) == (randomNumber1) % (randomNumber2))
textBox3.Text = "Correct!";
else
textBox3.Text = "Incorrect!";
}
}
}
and what I'm looking to do is if button 1 is clicked you add, button 2 you subtract, button 3 you multiply, button 4 you mod and then depending on which one was clicked you click submit and it'll tell you whether you got the right answer or not. What I currently have somewhat does that but if the answer is any of the four types of questions answers it'll show it as correct.
ie: the question is 8 + 3 and you put 5, it'll say correct because 8 - 3 is 5