First off, don;t create a new Random instance each time they press the button - move that to a private variable and use that instance each time - you will get a better random distribution of numbers that way.
private Random rnd = new Random();
private void btnNewProblem_Click(object sender, EventArgs e)
{
int x, y, z;
if (radAddition.Checked == true)
{
if (radSmallRange.Checked == true)
{
x = rnd.Next(0, 13);
...
}
Then, move
x
,
y
, and
z
to also be class level private variables:
private Random rnd = new Random();
private int x = -1;
private int y = -1;
private int z = -1;
private void btnNewProblem_Click(object sender, EventArgs e)
{
if (radAddition.Checked == true)
{
if (radSmallRange.Checked == true)
{
x = rnd.Next(0, 13);
...
}
Now your numbers are preserved as part of the class - so you can use them in both methods and you will reference the same values. (I set them to -1 both so they have a value, and so that you can check if a problem has been set when the use clicks the "answer" button)
Make sense?