问题描述
静态 void Main( 字符串 [] args) staticvoid Main(string[] args) { 字符串 播放器; string Players; int 玩家数; int numberofPlayers; 布尔 isValidInput = false ; bool isValidInput =false; 做 do { 控制台 .ForegroundColor = ConsoleColor .Cyan; Console.ForegroundColor =ConsoleColor.Cyan; 控制台 .Write( 如何 许多玩家 ); Console.Write("How many Players "); 问题在于字符串PlayerName所在的位置...之前一切正常... The problem is at where string PlayerName is at...Everything before that works fine... 玩家= 控制台 .ReadLine(); Console.ReadLine(); 控制台 .ForegroundColor = ConsoleColor .Green; Console.ForegroundColor =ConsoleColor.Green; 如果 ( int .TryParse(播放器, 输出 玩家数)) if (int.TryParse(Players,out numberofPlayers)) { 如果 (玩家数> 1&& 玩家人数< 10) if (numberofPlayers > 1 && numberofPlayers < 10) { isValidInput = isValidInput = true ; true; } } else else { } 如果 (isValidInput == false ) if (isValidInput ==false) { 控制台 .ForegroundColor = ConsoleColor .Red; Console.ForegroundColor =ConsoleColor.Red; 控制台 .WriteLine( 请 输入一个数字! " ); Console.WriteLine("Please Enter a Number! "); } } 同时 (!isValidInput); 此 是我遇到问题的地方,我希望它输入您的球员人数,并根据显示的人数输入姓名.然后选择名字,然后随机选择谁去争取,第二等,具体取决于您投入的玩家人数.... 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.... } } } 字符串 PlayerName; string PlayerName; { Console.Write( Console.Write( "输入您的姓名 ); "Enter your name "); PlayerName = Console.ReadLine(); PlayerName = Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); } Random randomGenerator = Random randomGenerator = 新 Random(Environment.TickCount); new Random(Environment.TickCount); for ( int i = 0;我<玩家人数; i ++) for (int i = 0; i < numberofPlayers; i++) { int randomCityIndex = randomGenerator.Next(numberofPlayers.Count ); int randomCityIndex = randomGenerator.Next(numberofPlayers.Count); 字符串 PlayerName = string PlayerName = PlayerName.Remove(PlayerName); PlayerName.Remove(PlayerName); Console.WriteLine( Console.WriteLine( 玩家{0}:{1}" ,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();