mardi 24 mars 2015

Randomize math symbol in c#

Can someone point me in the right direction to create a checktheanswer method when using a random math symbol? Here's the math problem.



Random random = new Random();
int num1 = random.Next(0, 100);
Label1.Text = Convert.ToString(num1);

char[] operators = { '+', '-', '*', '/' };
char op = operators[random.Next(operators.Length)];
label2.Text = Convert.ToString(op);

int num2 = random.Next(0, 100);
label3.Text = Convert.ToString(num2);


How do I write the method to include the random symbols? If it was fixed it would be (I think):



private bool CheckTheAnswer()
{
if (num1 + num2 == sum.Value)
return true;
else
return false;
}




Aucun commentaire:

Enregistrer un commentaire