# C# Tutorial – Math’s Quiz Game Version 2 in Windows Form Application and Visual Studio

In this tutorial we will be making a another math’s puzzle game. Instead of users entering the final sum of the numbers they will be guessing the symbol for the arithmetic calculations instead.  Find out which equation was used to get the result it shows on the app. This app only uses labels and keyboard event to work. Each time you answer successfully it will take you to the next question.

Lesson Objective –

1. Create a math’s quiz game
2. generate random numbers
3. work with switch statements
4. make the app respond to key presses

#### Full Source Code –

```using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Maths_Quiz_Version_2_MOO_ICT
{
public partial class Form1 : Form
{

int numA;
int numB;
int total;

Random rnd = new Random();
string[] Maths = {"Add", "Subtract", "Multiply" };

string userChoice;

public Form1()
{
InitializeComponent();
SetUpGame();
}

private void SetUpGame()
{

numA = rnd.Next(10, 20);
numB = rnd.Next(0, 9);

{
total = numA + numB;
break;

case "Subtract":
total = numA - numB;
break;

case "Multiply":
total = numA * numB;
break;
}

lblNumA.Text = numA.ToString();
lblNumB.Text = numB.ToString();
lblTotal.Text = total.ToString();
lblSymbol.Text = "?";
}

{

{
MessageBox.Show("Correct, Now try again!");
SetUpGame();
}
else
{
MessageBox.Show("Incorrect, try again!");
lblSymbol.Text = "?";
}

}

private void KeyIsUp(object sender, KeyEventArgs e)
{

if (e.KeyCode == Keys.Q)
{
lblSymbol.Text = "+";
}
if (e.KeyCode == Keys.W)
{
userChoice = "Subtract";
lblSymbol.Text = "-";
}
if (e.KeyCode == Keys.E)
{
userChoice = "Multiply";
lblSymbol.Text = "x";
}
}
}
}
```

### One response to “C# Tutorial – Math’s Quiz Game Version 2 in Windows Form Application and Visual Studio”

1. ZackIken says:

thanks dear