Tutorial 2: Create a Timed Math Quiz

Note

This article applies to Visual Studio 2015. If you're looking for Visual Studio 2017 documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2017. Download it here.

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.

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.

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