This program tests you on 10 questions that are 1 digit additions. When I run the code, the randomly generated Number1 value changes, however Number2 does not. Why isn't Number2 changing?
using System;
namespace Addition_test
{
class Program
{
static int Test()
{
int AnswersCorrect = 0;
for (int Counter = 0; Counter < 10; Counter++)
{
Random Num1 = new Random();
int Number1 = Num1.Next(1, 10);
Random Num2 = new Random(1);
int Number2 = Num2.Next(1, 10);
int Answer = Number1 + Number2;
Console.WriteLine("What is " + Number1 + "+" + Number2 + "?");
int Answer_entered = Convert.ToInt32(Console.ReadLine());
if (Answer_entered == Answer)
{
Console.WriteLine("Correct");
AnswersCorrect++;
}
else
{
Console.WriteLine("Incorrect");
}
}
return AnswersCorrect;
}
static void Main(string[] args)
{
int Result = Test();
Console.WriteLine("You got {0}/10 questions correct", Result);
Console.ReadLine();
}
}
}
Aucun commentaire:
Enregistrer un commentaire