我得到的错误是 error: expected ' ; ' before ' { ' token
我尝试通过添加 ;
来修复代码在 if (thisisanumber==5)
之后以及 else (thisisanumber!=5)
之后.虽然这解决了第一个错误,但它会产生另一个错误 error: ' else ' without a previous ' if '
.我真的很想知道我在编写代码时犯了什么错误,谢谢。
这是我的代码:
#include <iostream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Whats the Password?: ";
cin>> thisisanumber;
cin.ignore();
if (thisisanumber==5) {
cout<<"You've discovered the password! Wow, you're a genious you should be proud./n";
}
else (thisisanumber!=5) {
cout<<"You've failed in knowing the password and therefore cannot enter, leave and do not come back. Goodbye!/n";
}
cin.get();
}
最佳答案
您缺少关键字 if
:
else if (thisisanumber!=5) {
^^
或者,由于 thisisanumber == 5
的相反条件是 thisisanumber
不是 5,因此您不需要条件:
else {
关于c++ - 代码 : expected ' ; ' before ' { ' token -- what is causing this? 中的解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6500245/