lundi 23 décembre 2019

Random Equation Test. Correct or Wrong answer

I have been trying to write a test which involves random numbers to make equations for the user to answer. I have wrote it so that two int are assigned to a random number and the console writes the equation. I have used an if statement for the program to dictate whether the users answer is correct or incorrect. However it is always either correct or incorrect depending on the code i write. I can't write it so that the program decides the answer.

        int iE3 = rnd.Next(1, 11);
        int iE13 = rnd.Next(1, 11);
        int iA3 = iE3 * iE13;
        int answer3 = iE3 * iE13;
        Console.WriteLine("The third equation is {0} * {1}", iE3, iE13);
        Console.ReadLine();

        if ( answer3 == iA3)
        {
            Console.WriteLine("Well done you got it right!");
        }
        else
        {
            Console.WriteLine("Unfortunately you got it incorrect.");
        }



Aucun commentaire:

Enregistrer un commentaire