✅ Function For Division Game Showing Same Number Twice???
public void StartDivGame(string username, DateTime date, int totalQuestions, string difficulty)
{
int score = 0;
for (int i = 0; i < totalQuestions; i++)
{
int number1 = GetNumber(difficulty);
int number2 = GetNumber(difficulty);
while (number1 % number2 != 0 || number2 % number1 != 0)
{
number1 = GetNumber(difficulty);
number2 = GetNumber(difficulty);
}
int solution;
string question;
if (number2 > number1)
{
solution = number2 / number1;
question = $"{number2} / {number1}";
}
else
{
solution = number1 / number2;
question = $"{number1} / {number2}";
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write(question);
string guess = Console.ReadLine();
int input = Helpers.ValidateNumericInput(question, guess);
if (input == solution)
{
score++;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"\nYou Got It Right! Score: {score}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\nPress Any Key For Next Question");
Console.ReadLine();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\nOh No. You Got It Wrong. Next Question");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"Correct Solution: {solution}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\nPress Any Key For Next Question");
Console.ReadLine();
}
Console.Clear();
}
GameModel newGame = CreateGame(username, date, "Multiplication", score, totalQuestions, difficulty);
PreviousGames.SaveGame(newGame);
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Game Over! Press Any Key To Go To Main Menu");
Console.ReadLine();
GameMenu.ShowMenu(username, date);
}
public void StartDivGame(string username, DateTime date, int totalQuestions, string difficulty)
{
int score = 0;
for (int i = 0; i < totalQuestions; i++)
{
int number1 = GetNumber(difficulty);
int number2 = GetNumber(difficulty);
while (number1 % number2 != 0 || number2 % number1 != 0)
{
number1 = GetNumber(difficulty);
number2 = GetNumber(difficulty);
}
int solution;
string question;
if (number2 > number1)
{
solution = number2 / number1;
question = $"{number2} / {number1}";
}
else
{
solution = number1 / number2;
question = $"{number1} / {number2}";
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write(question);
string guess = Console.ReadLine();
int input = Helpers.ValidateNumericInput(question, guess);
if (input == solution)
{
score++;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"\nYou Got It Right! Score: {score}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\nPress Any Key For Next Question");
Console.ReadLine();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\nOh No. You Got It Wrong. Next Question");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"Correct Solution: {solution}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\nPress Any Key For Next Question");
Console.ReadLine();
}
Console.Clear();
}
GameModel newGame = CreateGame(username, date, "Multiplication", score, totalQuestions, difficulty);
PreviousGames.SaveGame(newGame);
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Game Over! Press Any Key To Go To Main Menu");
Console.ReadLine();
GameMenu.ShowMenu(username, date);
}
bigger number / smaller number
so if number1
is 7 and number2
is 15 then it would show as 15/7
. My problem is that it just consistently keeps showing the same number for both numbers like 27/27
and 53/53
instead of picking two random numbers. What do I have wong? Thanks0 Replies