mardi 12 juin 2018

Randomly assigning values from one array to another in C#

I am creating a program where I want to randomly assign world cup teams (32 fixed value) to people inputted by the user (unfixed value) and for it to keep assigning until all teams have been assigned or san no longer be shared evenly.

The teams are stored in an array and the players are stored in a list

    name = Console.ReadLine();
    inputtedNames.Add(name);

        while (name != "")
        {
            Console.WriteLine("Please enter another name or leave blank to finish: ");
            name = Console.ReadLine();
            inputtedNames.Add(name);
        }

...

    if (ans == "Y" || ans == "y")
        {
            Console.WriteLine("Press 1 to assign world cup 2018 teams to players or 2 to enter own teams");
            teams = Convert.ToInt32(Console.ReadLine());

            if (teams == 1)
            {
                foreach (string value in inputtedNames)
                {

                }
            }

Would I be able to create a new 2d array which store the players names in one column and randomly adds in team names in the next?

Any help is appreciated, let me know if the code is unclear.

Thanks.




Aucun commentaire:

Enregistrer un commentaire