我正在写一个二十一点程序。我创建了包含两个字符串和一个整数的类卡。 '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