jeudi 15 novembre 2018

Modulus operator with random numbers

What I want to do is have random numbers be generated and take those random numbers and put them through a modulus operator. And I want it to ask the user for the answer they think it is and then they will be told if it is right or wrong. This is what I have.

Random rand = new Random();
int minA;
int maxA;
int minB;
int maxB;
int usersAnswer;

Console.WriteLine("what is the minimum value: ");
Int32.TryParse(Console.WriteLine(), out minA);

Console.WriteLine("what is the minimum value: ");
Int32.TryParse(Console.WriteLine(), out maxA);

Console.WriteLine("what is the minimum value: ");
Int32.TryParse(Console.WriteLine(), out minB);

Console.WriteLine("what is the minimum value: ");
Int32.TryParse(Console.WriteLine(), out maxB);

Console.WriteLine("What is the result of {0} % {1}? ", rand.Next(minA, maxA), rand.Next(minB, maxB)); 
Int32.TryParse(Console.ReadLine(), out usersAnswer);
answer = //directly implementing the random numbers generated with modulous operator)
if(userAnswer == answer)
{
    Console.WriteLine("{0} is correct", answer);
}
else
{
    Console.WriteLine("Good try, but no: {the random number} % {the other random number} = {0}", not sure, not sure, answer)
}    

So what I want to know is how I can directly implement the random numbers already generated from "Console.WriteLine("What is the result of {0} % {1}? ", rand.Next(minA, maxA), rand.Next(minB, maxB));" into a modulus operator equation and get the answer. I hope this all made sense




Aucun commentaire:

Enregistrer un commentaire