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

来源:百度知道 编辑:UC知道 时间:2024/07/04 23:25:33
#include <stdio.h>
void main()
{
char n;
int i,j;
for(j=0;j<3;j++)
{
printf("\nenter your name key( 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 134679");
getchar();
}
新手。。。。。。 就是有三次输入的机会,只有输入wo才能得到答案000000,但是当它运行时只有第一次有进行判断,第二次不进行判断直接显示error!!!!!!,第三次又正常,一直找不出原因,头疼中。。。(if(i==0&&n!='w'||i==1&&n!='o')改成if((i==0&&n!='w')||(i==1&&n!='o'))也不行。。

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);

本地的运行结果
F:\Dev-Cpp\my>zd3

enter your key(just two)(you have get three change, this is the 1th change):
w

enter your key(just two)(you have get three change, this is the 1th change):
e
error!!!!!!!!!!
//第一次w正确,e错误
enter your key(just two)(you have get three change, this is the 2th change):
e
error!!!!!!!!!!
第二次 e错误不向下执行了
enter your key(just two)(you have get three change, this is the 3th change):
w

enter your key(just two)(you have get three change, this is the 3th change):
o
the key is 000000

第三次两个都正确