显示用户输入时出现问题 [英] Problem displaying user input

查看:98
本文介绍了显示用户输入时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main(string[] args)

{

string Players;

int numberofPlayers;

bool isValidInput = false;

do

{

Console.ForegroundColor = ConsoleColor.Cyan;

);

Console.Write("How many Players ");

问题在于字符串PlayerName所在的位置...之前一切正常...

The problem is at where string PlayerName is at...Everything before that works fine...

玩家=

Console.ReadLine();

Console.ForegroundColor = ConsoleColor.Green;

int .TryParse(播放器,

if (int.TryParse(Players, out numberofPlayers))

{

if (numberofPlayers > 1 && numberofPlayers < 10)

{

isValidInput =

isValidInput =

true;

}

}

else

{

}

if (isValidInput == false)

{

Console.ForegroundColor = ConsoleColor.Red;

);

Console.WriteLine("Please Enter a Number! ");

}

}

此 是我遇到问题的地方,我希望它输入您的球员人数,并根据显示的人数输入姓名.然后选择名字,然后随机选择谁去争取,第二等,具体取决于您投入的玩家人数....

while (!isValidInput);This is where i am having problems, I want it to where you enter the number of players, and depending on that number it displays enter the names. then takes the names and random selects who goes forst, second and so on depending ont he number of players you put.... 

}

}

}

string PlayerName;

{

Console.Write(

Console.Write(

"Enter your name ");

PlayerName = Console.ReadLine();

PlayerName = Console.ReadLine();

Console.ReadLine();

Console.ReadLine();

}

Random randomGenerator =

Random randomGenerator =

new Random(Environment.TickCount);

int i = 0;我<玩家人数; i ++)

for (int i = 0; i < numberofPlayers; i++)

{

int randomCityIndex = randomGenerator.Next(numberofPlayers.Count);

string PlayerName =

PlayerName.Remove(PlayerName);

PlayerName.Remove(PlayerName);

Console.WriteLine(

Console.WriteLine(

,i + 1,PlayerName);

"Player {0} : {1}", i + 1, PlayerName);

}

Console.ReadLine();

Console.ReadLine();

}

}

推荐答案

查看是否有效

            string Players;
            int numberofPlayers;
            bool isValidInput = false;

            do
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("How many Players ");
                Players = Console.ReadLine();
                Console.ForegroundColor = ConsoleColor.Green;

                if (int.TryParse(Players, out numberofPlayers))
                {
                    if (numberofPlayers > 1 && numberofPlayers < 10)
                    {
                        isValidInput = true;
                    }
                }
                else
                {

                }
                if (isValidInput == false)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Please Enter a Number! ");
                }
            }
            while (!isValidInput);

            string PlayerName;
            Console.Write("Enter your name ");

            PlayerName = Console.ReadLine();
            Console.ReadLine();
            Random randomGenerator = new Random(Environment.TickCount);

            for (int i = 0; i < numberofPlayers; i++)
            {
                int randomCityIndex = randomGenerator.Next(numberofPlayers);
                PlayerName = PlayerName.Remove(numberofPlayers);
                Console.WriteLine("Player {0} : {1}", i + 1, PlayerName);
            }

            Console.ReadLine();


这篇关于显示用户输入时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆