|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
int main()//-------------------------------------------------------------------如何去除运行之后的两个密码不正确
{
//int conut = 0;
char real_answer,a;
real_answer = '阿瑶666';
printf("请输入正确的密码:");
//scanf("%c",&a);
do
{
if (getchar() == real_answer)
{
printf("密码正确");
break;
}
else
{
printf("密码不正确!");
//break;
}
}
while (getchar() != '\n');
return 0;
}
本帖最后由 jackz007 于 2021-12-13 21:16 编辑
- #include<stdio.h>
- int main(void)
- {
- int f , i , j , k , n = 5 ;
- char c , real_answer[] = "阿瑶666" , pwd[256] ;
- for(f = i = 0 ; i < n ; i ++) {
- for(j = 0 ; (c = getchar()) != '\n' ; j ++ , pwd[j] = '\0') pwd[j] = c ;
- for(k = 0 ; k < j && real_answer[k] && pwd[k] ; k ++) ;
- if(! real_answer[k] && ! pwd[k]) {
- printf("密码正确。\n") ;
- f = 1 ;
- break ;
- } else {
- printf("密码错误\n\n") ;
- }
- }
- if(! f) printf("很遗憾,%d 次机会已经用完!\n" , n) ;
- }
复制代码
编译、运行实况
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- 阿瑶666
- 密码正确。
- D:\00.Excise\C>x
- 123
- 密码错误
- aaa
- 密码错误
- bbb
- 密码错误
- ccc
- 密码错误
- ddd
- 密码错误
- 很遗憾,5 次机会已经用完!
- D:\00.Excise\C>
复制代码
|
|