C++ errorC2181 illegal else without matching if

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{

time_t now;
time(&now);
srand(now);
rand();

float choice1,choice2;
choice1=1;
choice2=1;

cout<<"do u want to start?(1:yes,any key:no)"<<endl;
cin>>choice1;
if(choice1==1)
{

while(choice2==1)
{

cout<< "winning number is"<< endl;

for (int i=0; i<7; i++){

cout << (rand() % 40)+1 << endl;
}
cout<< "additional number is"<< endl;
for (int i=0; i<1; i++){

cout << (rand() % 40)+1 << endl;
}
else
{
cout<<"byebye~"<<endl;
}
cout<<"Do u want to continue?(Y:yes,any key:no)"<<endl;
fflush(stdin);
cin>>choice2;
if(choice2==1){
while(choice2==1)
{

cout<< "winning number is"<< endl;

for (int i=0; i<7; i++){

cout << (rand() % 40)+1 << endl;
}
cout<< "additional number is"<< endl;
for (int i=0; i<1; i++){

cout << (rand() % 40)+1 << endl;
}
}
}
}
else
{cout<<"BYEBYE";
}

return 0;
}

哪位高人指点指点,因为我是初学者有if else那个晕了,括号好像用太多了,不知道怎么的了。

你的if和else都要成对出现才行!而且最后还少了一个花括号,i也被重新定义了两次...你再重新修改后看看。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-03
先用if然后再用else,if 与else要成对出现
第2个回答  2011-01-03
你可以用Vs2010编辑器,他有可以区分括号的能力。。
相似回答