We recommend using Visual Studio 2017

Tutorial 2: Create a Timed Math Quiz


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Tutorial 2: Create a Timed Math Quiz.

In this tutorial, you build a quiz in which the quiz taker must answer four random arithmetic problems within a specified time. You learn how to:

  • Generate random numbers by using the Random class.

  • Trigger events to occur at a specific time by using a Timer control.

  • Control program flow by using if else statements.

  • Perform basic arithmetic operations in code.

When you finish, your quiz will look like the following picture, except with different numbers.

Math quiz with four problems
Quiz that you create in this tutorial

To download a completed version of the quiz, see Complete Math Quiz tutorial sample.

System_CAPS_ICON_note.jpg Note

This tutorial covers both Visual C# and Visual Basic, so focus on the information that's specific to the programming language that you're using.

Step 1: Create a Project and Add Labels to Your FormStart by creating the project, changing properties, and adding Label controls.
Step 2: Create a Random Addition ProblemCreate an addition problem, and use the Random class to generate random numbers.
Step 3: Add a Countdown TimerAdd a countdown timer so that the quiz can be timed.
Step 4: Add the CheckTheAnswer() MethodAdd a method to check whether the quiz taker entered a correct answer for the problem.
Step 5: Add Enter Event Handlers for the NumericUpDown ControlsAdd event handlers that make your quiz easier to take.
Step 6: Add a Subtraction ProblemAdd a subtraction problem that generates random numbers, uses the timer, and checks for correct answers.
Step 7: Add Multiplication and Division ProblemsAdd multiplication and division problems that generate random numbers, use the timer, and check for correct answers.
Step 8: Customize the QuizTry other features, such as changing colors and adding a hint.