显示用户输入时出现问题 [英] Problem displaying user input
问题描述
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(); } } 查看是否有效 这篇关于显示用户输入时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!推荐答案
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();