Share via


Tutorial 3: Create a Math Quiz

In this tutorial, you build a timed math quiz game, where the player must answer four random arithmetic problems within a specified time. You learn how to:

  • Generate random numbers using the Random class.

  • Trigger events using a Timer control.

  • Control program flow using if else statements.

  • Perform basic arithmetic operations.

When you finish, your program will look like the following picture.

Game that you create in this tutorial

Math quiz with four problems

Note

In this tutorial, both Visual C# and Visual Basic are covered, so focus on information specific to the programming language that you're using.

Title

Description

Step 1: Create a Project and Add Labels to Your Form

Begin by creating the project, changing properties, and adding Label controls.

Step 2: Create a Random Addition Problem

Create an addition problem that generates random numbers using the Random class.

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 for correct answers.

Step 5: Add Enter Event Handlers for the NumericUpDown Controls

Add event handlers to make your program easier to use.

Step 6: Add a Subtraction Problem

Add a subtraction problem that generates random numbers. Check for correct answers and use the timer.

Step 7: Add Multiplication and Division Problems

Add multiplication and division problems that generate random numbers. Check for correct answers and use the timer.

Step 8: Try Other Features

Try other features, such as changing colors and adding a hint.