我是 C++ 的新手,并且一直盯着我的(可能很糟糕的)代码有一段时间了,不知道它有什么问题。
我正在尝试遍历 if 和 else 语句的几次迭代,并且必须在语法上做一些不正确的事情 - 因为它显示了“else without a previous if”的编译器错误
这是一门课,我正在努力解决,但如果你看到一些明显的我忽略的东西,我很想知道。
谢谢!
for (i = 0; i < iterationsNum; i++){
if (charlieAlive == 0) // Aarron's shot
{
if (aaronShot() == 1)
charlieAlive = 1;
}
else (charlieAlive == 1 && bobAlive == 0);{
if (aaronShot() == 1)
bobAlive = 1;
}
else (charlieAlive == 1 && bobAlive == 1 && aaronAlive == 0);{
cout << "Aaron is the Winner!\n";
totalShot++;
aaronCounter++;
}
continue;
if (charlieAlive == 0 && aaronAlive ==0) // Bob's shot
{
if (bobShot() == 1)
charlieAlive = 1;
}
else (charlieAlive == 1 && aaronAlive == 0);{
if (bobShot() == 1)
aaronAlive = 1;
}
else (charlieAlive == 1 && aaronAlive == 1 && bobAlive == 0);{
cout << "Bob is the Winner!\n";
bobCounter++;
totalShot++;
}
continue;
if (charlieAlive == 0 && bobAlive == 0) // Charlie's shot
{
bobAlive = 1;
}
else (charlieAlive == 0 && bobAlive == 1 && aaronAlive == 0);{
aaronAlive = 1;
totalShot++;
}
else (charlieAlive == 0 && bobAlive == 1 && aaronAlive == 1);{
cout << "Charlie is the Winner!\n";
}
continue;