# Step 7: Add Multiplication and Division Problems

**Visual Studio 2010**

Before you begin this procedure, think about how you will add multiplication and division problems. Consider the initial step, which involves storing values.

### To add multiplication and division problems

Add four ints (Integers) to the form. The code should look like the following.

public partial class Form1 : Form { // Create a Random object to generate random numbers. Random randomizer = new Random(); // These ints will store the numbers for the addition problem. int addend1; int addend2; // These ints will store the numbers for the subtraction problem. int minuend; int subtrahend; // These ints will store the numbers for the multiplication problem. int multiplicand; int multiplier; // These ints will store the numbers for the division problem. int dividend; int divisor; // This int will keep track of the time left. int timeLeft;

Like before, modify the

**StartTheQuiz()**method to fill in random multiplication and division problems. The code should look like the following./// <summary> /// Start the quiz by filling in all of the problems /// and starting the timer. /// </summary> public void StartTheQuiz() { // Fill in the addition problem. addend1 = randomizer.Next(51); addend2 = randomizer.Next(51); plusLeftLabel.Text = addend1.ToString(); plusRightLabel.Text = addend2.ToString(); sum.Value = 0; // Fill in the subtraction problem. minuend = randomizer.Next(1, 101); subtrahend = randomizer.Next(1, minuend); minusLeftLabel.Text = minuend.ToString(); minusRightLabel.Text = subtrahend.ToString(); difference.Value = 0; // Fill in the multiplication problem. multiplicand = randomizer.Next(2, 11); multiplier = randomizer.Next(2, 11); timesLeftLabel.Text = multiplicand.ToString(); timesRightLabel.Text = multiplier.ToString(); product.Value = 0; // Fill in the division problem. divisor = randomizer.Next(2, 11); int temporaryQuotient = randomizer.Next(2, 11); dividend = divisor * temporaryQuotient; dividedLeftLabel.Text = dividend.ToString(); dividedRightLabel.Text = divisor.ToString(); quotient.Value = 0; // Start the timer. timeLeft = 30; timeLabel.Text = "30 seconds"; timer1.Start(); }

Modify the

**CheckTheAnswer()**method so that the method also checks the multiplication and division problems. The code should look like the following./// <summary> /// Check the answer to see if the user got everything right. /// </summary> /// <returns>True if the answer's correct, false otherwise.</returns> private bool CheckTheAnswer() { if ((addend1 + addend2 == sum.Value) && (minuend - subtrahend == difference.Value) && (multiplicand * multiplier == product.Value) && (dividend / divisor == quotient.Value)) return true; else return false; }

**Note**Because there's no simple way to enter the multiplication sign (×) and the division sign (÷) using the keyboard, Visual C# and Visual Basic use an asterisk (*) for multiplication and a slash mark (/) for division.

Change the last part of the timer's Tick event handler so it fills in the correct answer when time runs out. The code should look like the following.

else { // If the user ran out of time, stop the timer, show // a MessageBox, and fill in the answers. timer1.Stop(); timeLabel.Text = "Time's up!"; MessageBox.Show("You didn't finish in time.", "Sorry"); sum.Value = addend1 + addend2; difference.Value = minuend - subtrahend; product.Value = multiplicand * multiplier; quotient.Value = dividend / divisor; startButton.Enabled = true; }

Save and run your program. Now, four problems must be answered to complete the quiz, as shown in the following picture.

### To continue or review

To go to the next tutorial step, see Step 8: Try Other Features.

To return to the previous tutorial step, see Step 6: Add a Subtraction Problem.