I am working on code for a slot machine game and I am having trouble generating a random word from a list. This is what I have currently but I am unable to random generate a word from this list. I just need help determining the problem.
static void SlotMachine()
{
Random rand = new Random();
var list = new List<string>{ "Elephant", "Computer", "Football", "Resume", "Capstone", "Crimson" };
var randomList = random.Next(list.Count);
Console.Write("Enter amount of gil you want to risk: ");
double gil = Convert.ToDouble( Console.ReadLine());
double winningAmount = 0;
for (int i = 1; i <= 3; i++)
{
string word = list[rand.Next(list.Count)];
randomList.Add(word);
Console.Write(word+" ");
}
Console.WriteLine();
if (randomList[0] == randomList[1] && randomList[1] == randomList[2])
{
winningAmount = gil*3;
}
else if(randomList[0] == randomList[1] || randomList[0] == randomList[2] || randomList[2] == randomList[1])
{
winningAmount = gil * 2;
}
else
{
winningAmount = 0;
}
Console.WriteLine("Winning amount is {0} ",winningAmount);
}
static void Dice()
{
Random r = new Random();
int val1 = r.Next(1,7);
int val2 = r.Next(1,7);
int val3 = r.Next(1,7);
int val4 = r.Next(1,7);
int val5 = r.Next(1,7);
int sum = val1 + val2 + val3 + val4 + val5;
int i = 1;
for(i = 1; i<=4; ++i)
{
Console.WriteLine("Guess a number between 5 and 30: ");
int n = Convert.ToInt32(Console.ReadLine());
if ( sum == n)
{
Console.WriteLine("You have Guessed It Correctly and you win 50gil");
break;
}
else if ( n > sum)
Console.WriteLine("Too High");
else
Console.WriteLine("Too Low");
}
if(i==5)
Console.WriteLine("Not able to Guess in 4 times, Thanks for playing");
}