我對c#非常陌生,並且在處理基本程序時收到此錯誤(錯誤只能將賦值,調用,遞增,遞減,等待和新對象表達式用作聲明),並無法弄清楚它出現的原因。if/else語句中的語法錯誤
if (pizzaDiameter >= 12 && pizzaDiameter < 16)// begin nested if statement
{
Console.WriteLine("A" + pizzaDiameter + "will yield 8 slices.");
}
else if (pizzaDiameter >= 16 && pizzaDiameter < 24)//Second pizza diameter range
{
Console.WriteLine("A" + pizzaDiameter + "will yield 12 slices.");
}
else if (pizzaDiameter >= 24 && pizzaDiameter < 30)
{
Console.WriteLine("A" + pizzaDiameter + "will yield 16 slices.");
}
else (pizzaDiameter >= 24 && pizzaDiameter <= 30)
{
Console.WriteLine("A" + pizzaDiameter + "will yield 24 slices.");
}
else // pizza diameter was not a whole number
{
Console.WriteLine("Pizza diameter must be between 12-36 inclusive.");// Error appears here.
}
else //pizza diameter must be between 12-36
{
Console.WriteLine("Pizza diameter must be a whole number.");
}
你的第一個'else'應該是'否則,如果',否則你應該刪除條件語句。 – 2014-10-05 18:05:10
我已經重新縮進您的代碼以顯示實際的縮進級別。有兩個'如果'缺少。 – poke 2014-10-05 18:07:09
謝謝,我一直在盯着這一個小時不確定問題是什麼:) – Ryan 2014-10-05 18:07:52