So I'm building a small math game where random sums are generated and, upon being answered, added to either a right or wrong score. It's going well, and I've received some help with certain things and learnt along the way, but I've hit another problem I can't figure out. The game picks between +, -, * and / operators when generating sums, and +, - and * work well, but / often calls for a decimal answer which the program does not like. I'd like to try to figure out a way to make it not generate a number to divide by that would result in a decimal answer when diving the first number. Here's some example code to clear what I have so far up:
var randomNum = new Random();
num1 = randomNum.Next(0, 10);
num2 = randomNum.Next(0, 10);
char[] operators = { '+', '-', '*', '/' };
char op = operators[randomNum.Next(operators.Length)];
switch (op)
{
case '+':
answer = num1 + num2;
label1.Text = num1.ToString() + " + " + num2.ToString() + " = ";
break;
case '-':
answer = num1 - num2;
label1.Text = num1.ToString() + " - " + num2.ToString() + " = ";
break;
case '*':
answer = num1 * num2;
label1.Text = num1.ToString() + " * " + num2.ToString() + " = ";
break;
case '/':
answer = num1 / num2;
label1.Text = num1.ToString() + " / " + num2.ToString() + " = ";
break;
}
I've tried moving the bits that state what num1 and num2 are into each of the cases, so that they look like this:
case '/':
num1 = randomNum.Next(0, 10);
num2 = randomNum.Next(0, 10);
answer = num1 / num2;
label1.Text = num1.ToString() + " / " + num2.ToString() + " = ";
break;
But I can't conceive of what I could put in the brackets instead of having (0, 10) to avoid decimal sum answers. Is there a way I can have it determine if an answer will be a decimal one, and if it is re-roll num2 to try and get a whole number answer? Thanks!