使用capl写一串代码,要求账号为fanmao,密码为123456,如果账号不为fanmao且密码为123456,输出账号错误,如果账号为fanmao且密码不为123456,输出密码错误
时间: 2023-12-14 14:39:41 浏览: 39
以下是使用CAPL语言编写的代码:
```
variables
{
message msg;
char username[10];
char password[10];
}
on key 'S'
{
getVarString(username, sizeof(username), "Enter username:");
getVarString(password, sizeof(password), "Enter password:");
if(strcmp(username, "fanmao") != 0 && strcmp(password, "123456") == 0)
{
msg = "Username incorrect!";
write(msg);
}
else if(strcmp(username, "fanmao") == 0 && strcmp(password, "123456") != 0)
{
msg = "Password incorrect!";
write(msg);
}
else if(strcmp(username, "fanmao") != 0 && strcmp(password, "123456") != 0)
{
msg = "Username and password incorrect!";
write(msg);
}
else
{
msg = "Login successful!";
write(msg);
}
}
```
以上代码会在按下键盘上的'S'键时触发,然后提示用户输入用户名和密码。如果输入的用户名不是'fanmao',但是密码是'123456',则会输出'Username incorrect!'。如果输入的用户名是'fanmao',但是密码不是'123456',则会输出'Password incorrect!'。如果用户名和密码都不正确,则会输出'Username and password incorrect!'。如果用户名和密码都正确,则会输出'Login successful!'。
阅读全文