namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
// Populate the string array with names of members in the Draw
string[] names = { "Mr.Smith", "Mr.John", "Mr.Bill","Mr.Jason","Mr.Ahmad","Ms.Susan","Ms.Julia","Mr.Ben","Mr.Ken","Mr.Singh","Mr.Khan","Mr.Benny","Ms.Molly","Mr.Page","Mr.Jeff","Mrs.Kelly","Mrs.Rima","Ms.Hina","Mr.Ramesh","Mr.Amit" };
// Populate the List from the string array
List<string> namesList = new List<string>(names);
int ch;
int num;
Random rnd = new Random();
do
{
Console.WriteLine("\nMenu\n1. Draw\n2. Reset\n3. Exit\nEnter your choice : ");
ch = Convert.ToInt32(Console.ReadLine());
switch (ch)
{
case 1:
// Draw a winner if all members have not already been selected
if (namesList.Count > 0)
{
// Generate a random number between 0 and size of namesList who is the winner
num = rnd.Next(0, namesList.Count);
// Display the winner on console
Console.WriteLine("\nWinner of raffle draw is " + namesList[num]);
// Remove the winner from the list display count of remaining members
namesList.RemoveAt(num);
Console.WriteLine(namesList.Count + " members remaining to win ");
}
else
{
// All 20 winners have already been selected . Ask the user to Reset
Console.WriteLine("\nAll Winners have been selected. Reset the list to draw a new winner ");
}
break;
case 2:
// Reset the members
Console.WriteLine("\nResetting the draw");
// Clear the old List
namesList.Clear();
// Add the original elements back to the List from names string array
foreach (var rec in names)
namesList.Add(rec);
break;
case 3:
// Exit the program
Console.WriteLine("Exiting the program");
break;