Well...What happens if num1 is 11 and num2 is 14, and RandOperation is 74?
It passes this test:
if (RandOperation % 2 == 0)
But it fails this test:
if (num2 % num1 == 0 & num2 > num1)
And it fails this test:
if (num1 % num2 == 0 & num1 > num2)
So...it doesn't do anything to
total
at all, and you get a zero.
Try it: use the debugger and follow the execution through - you'll see what I mean!
"Ok I will try, but maybe there is a simple way to generate what I want?"
Well...that's going to depend on exactly what you want! :laugh:
I'm not sure why you are using the remainder in the if conditions at all - the way I'd do it is a bit simpler:
Random rand = new Random();
int num1 = rand.Next(1, 15);
int num2 = rand.Next(1, 15);
int RandOperation = rand.Next(0, 2);
if (RandOperation == 0)
{
if (num1 < num2)
{
int temp = num1;
num1 = num2;
num2 = temp;
}
Display.Text = string.Format("{0} / {1}", num1, num2);
total = num1 / num2;
}
else
{
Display.Text = string.Format("{0} * {1}", num1, num2);
total = num1 * num2;
}