I'm trying to write a beginner program, where I roll 2 dies, and it tests the dies, if there's any evens it will say "evens are better then odds" and if there's a scenario where there's only odds it will say, "Odds are still cool", and after each roll it will ask the user if they want to play again, if not it will tell the user how many times they rolled the die. When I run the program, it will run, and ask the user if they want to roll again, when I type "YES" it runs infinitely. I don't know if the problem has to do with how my main method is written or if it's the TinasDice method.
I've tried going about using only the if/else statement in the main method where the user's input is tested, but that immediately exits out of the program.
TinasDice();
Console.WriteLine("Do you want to play again?");
string answer;
int counter = 0;
answer = Console.ReadLine();
while (answer == "YES")
{
if (answer == "YES")
{
TinasDice();
}
else
{
Console.WriteLine("The number of times the dice was die was thrown is: " + counter);
Console.WriteLine("Nice game!");
Console.WriteLine("Thanks for playing. Come play again soon!");
}
}
}
public static void TinasDice()
{
Random random = new Random();
int dice1 = new int();
int dice2 = new int();
dice1 = random.Next(1, 6);
dice2 = random.Next(1, 6);
Console.WriteLine("Hey Welcome to Tina's Dice Game.");
Console.WriteLine("Let's start!");
if (dice1 % 2 == 0 || dice2 % 2 == 0)
{
Console.WriteLine("I got " + dice1 + " and " + dice2);
Console.WriteLine("Evens are better then odds!");
}
else
{
Console.WriteLine("I got a " + dice1 + " and " + dice2);
Console.WriteLine("Odds ares still cool!");
}
I'm just trying to get the program to run incrementally after TinasDice is ran the first time, so when the user types "YES" it will run TinasDice once, and then prompt the user again, until the user types something else other then "YES".