高手帮我看下这个很简单的程序(c程序)。。。。哪错了

来源:百度知道 编辑:UC知道 时间:2024/06/24 07:58:02
#include <stdio.h>
void main()
{
char n;
int i,j;
for(j=0;j<3;j++)
{
printf("\nenter your key(just two)(you have get three change, this is the %dth change):\n",j+1);
for(i=0;i<2;i++)
{
n=getchar();
if(i==0&&n!='w'||i==1&&n!='o')
{
printf("error!!!!!!!!!!" );
i=9;
}
}
if(i==2)break;
}
if(i==2)
printf("the key is 000000");
getchar();
}
就是想有三次输入的机会,来得到000000的答案,可是第一次会进行判断,j循环第二次循环时就不进行判断直接显示error。。。。第三次又正常了。。。。。。但输入正确时都会显示答案的。。。一直很郁闷找不出哪里错。。高手帮帮忙啊
加没加括号不影响它的顺序。。。还是不行啊。。。。又是原来的症状。。。。

1这地方改一下,
if(i==0&&n!='w'||i==1&&n!='o')
改成if((i==0&&n!='w')||(i==1&&n!='o'))
加括号和不加是不一样的

2,
if(i==0&&n!='w'||i==1&&n!='o')
{
printf("error!!!!!!!!!!" );
i=9;
}
这下面加一个
fflush(stdin);