Respuesta :
Answer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace P739 {
class P739 {
private static Random random = new Random();
private static int randomNumber1 = 0;
private static int randomNuber2 = 0;
private static int multiplicationResult = 0;
private static bool isNeedToShowQuestionAgain = false;
// Methods
private static int RandomNumber (int min, int max) {
return random.Next(min,max);
}
private static void GenerateQuestion (bool isNeedToShowQuestion) {
if (!isNeedToShowQuestionAgain) {
randomNumber1 = RandomNumber(0, 9);
randomNumber2 = RandomNumber(0, 9);
}
PrintQuestion();
}
private static void PrintQuestion() {
Console.WriteLine(string.Format("How much is {0} times {1}?", randomNumber1, randomNuber2));
}
// Main
static void Main() {
while (true) {
int userInput=0;
GenerateQuestion(isNeedToShowQuestionAgain);
try {
userInput = Convert.ToInt32(Console.ReadLine());
}
catch {
}
if (userInput == multiplicationResult) {
Console.WriteLine("very good! your answer is correct.");
isNeedToShowQuestionAgain = false;
}
else {
Console.WriteLine("No.Please try again.");
isNeedToShowQuestionAgain = true;
}
}
}
}
}
Explanation:
The problem was in your GenerateQuestion method. You weren't generating new random numbers and setting them to the two random number variables. Hence the same original random numbers were kept.
Also there was a bug in GenerateQuestion method where PrintQuestion() was not being called if isNeedToShowQuestionAgain = true.