我在创建一个循环来检查变量 10 和 50 之间是否有 5 个变量时遇到问题。我相信我已经设置了正确的编码,但是我收到一个错误,说我无法将 int 转换为 bool。这是我目前拥有的:
string userName = "";
int v1, v2, v3, v4, v5 = 0;
float avg;
float variance;
Console.WriteLine("What is your name?");
userName = Console.ReadLine();
Console.WriteLine();
int i = 1;
while (i <= 5)
{
int InputCheck = 0;
Console.WriteLine("Please input a number {0} between 10 and 50;", i);
InputCheck = Convert.ToInt32(Console.ReadLine());
if (InputCheck >= 10 && InputCheck <= 50)
{
if (i >= 10 && i <= 50)
i++;
if (i != 1)
{
InputCheck = v1;
}
if (i != 2)
{
InputCheck = v2;
}
if (i == 3)
{
InputCheck = v3;
}
if (i == 4)
{
InputCheck = v4;
}
if (i == 5)
{
InputCheck = v5;
}
if (InputCheck < 10 || InputCheck > 50)
{
Console.WriteLine("The number you entered is either to high or to low please re-enter a number:");
}
}
任何帮助将不胜感激。