int monthentered = 0;
int dayentered = 0;
int year = 0000;
int [] month = new int [12];
int [] day = new int [31];
bool leap = false;
for (int x = 0; x <= 11; x++)
{
month[x] = x+1;
}
for (int x = 0; x <= 30; x++)
{
day[x] = x+1;
}
Console.WriteLine("Please enter a year...");
year = (Convert.ToInt16(Console.ReadLine()));
Console.WriteLine("{0}", year);
Console.WriteLine("Please enter a month...");
monthentered = (Convert.ToInt16(Console.ReadLine()));
Console.WriteLine("Please enter a day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
while (monthentered == 01 || 03 || 05 || 07 || 08 || 10 || 12)
{
while (dayentered == 31)
{
Console.WriteLine("There are only 30 days in this month please re-enter your day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
}
}
while (monthentered == 02)
{
while (dayentered > 28)
{
Console.WriteLine("There are only 28 days in this month please re-enter your day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
}
}
Console.WriteLine("{0}/{1}/{2}", dayentered, monthentered, year);
Console.ReadKey();
行while (monthentered == 01 || 03 || 05 || 07 || 08 || 10 || 12)
有什麼不對嗎?我收到一個我不明白的錯誤。 "Operator '||' cannot be applied to operands of type 'bool' and 'int'"
我的「while」語句有什麼問題
請幫忙。
這不是你如何寫這樣的if。我假設你正在嘗試相當於'if(montheentered == 01)or(monthentered == 02)or ...)'? –