我正在寫一個二十一點程序。我創建了包含兩個字符串和一個整數的類卡。 'dealer'是'card'類的向量,'dtotal'和'deckplace'都是整數。 'display()'是打印卡片,套裝和總數的函數。該錯誤發生在「else if(total> 16)」上方的行中。錯誤C2059:語法錯誤:'}'
void dealerTurn()
{
if (dtotal<17)
{
do while (dtotal<17)
{
dealer.pop_back(deck[deckplace]);
deckplace = deckplace+1;
for (y=0;y<dealer.size();y++)
{
if (dealer[y].name=="A" && dtotal>21)
{
dealer[y].value = 1;
dtotal = 0;
for (z=0;z<dealer.size();z++)
dtotal = dtotal + dealer[z].value;
}
}
display();
if (dtotal>21)
{
cout << endl << "-----DEALER BUSTED!-----" << endl << endl;
dtotal = 0;
}
}
}
else if (total>16)
{
display();
}
result();
}
'do while' ?????????????????? – Mysticial
我覺得這樣做很糟糕,但-1因爲沒有研究,因爲你的C++書沒有教你'做while(X){Y}'。這意味着你做了它,並沒有看到它失敗時。 –
我沒有從書中學習C++。我不認爲do循環會導致這種語法。我在發佈之前研究了此語法錯誤的其他示例。 – user1978932