编写程序模拟简单的密码登录

编写程序模拟简单的密码登录,首先从键盘输入名字和密码,若密码正确则给出问候语。 
若密码不正确,则给出错误提示,并允许再次输入,直到输入正确的密码或0结束。 
用户名随意,不超过10个字节。 
密码123456 

# include <stdio.h>
int main()
{
    char name[10];
    scanf("%s",name);
    while(1)
    {
        int password;
        scanf("%d",&password);
        if(password==0)
        {
            printf("Wrong Password!\n");
            break;
        }
        if(password==123456)
        {
            printf("Hello %s\n",name);
            break;
        }
        else
        {
            printf("Wrong Password!\n");
            continue;
        }
    }
    return 0;
}

一开始把密码设置成字符串,比较麻烦。后来想了想直接int就OK了

猜你喜欢

转载自blog.csdn.net/Jason6620/article/details/83184597