The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary-school student learn multiplication. Use a Random object to produce two positive one-digit integers. The program should then prompt the user with a question, such asHow much is 6 times 7?The student then inputs the answer. Next, the program checks the student’s answer. If it is correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student gets it right. A separate method should be used to generate each new question. This method should be called once when the app begins execution and each time the user answers the question correctly.here is the code that I have but for some reason, I keep getting the same question (0 * 0) can you help me figure out what I did wrong or do this problem tnxusing 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; private static int RandomNumber (int min, int max){return random.Next(min,max);}private static void GenerateQuestion (bool isNeedToShowQuestion){if (!isNeedToShowQuestionAgain)PrintQuestion(); }private static void PrintQuestion(){Console.WriteLine(string.Format("How much is {0} times {1}?", randomNumber1, randomNuber2));} 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;}}}}}

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.

ACCESS MORE
EDU ACCESS
Universidad de Mexico