please help me write the code with C++ to display login interface
时间: 2024-05-05 20:15:19 浏览: 10
Here is a simple example of a login interface in C:
```
#include <stdio.h>
#include <string.h>
int main() {
char username[20];
char password[20];
int attempts = 3;
printf("Please enter your username and password:\n");
do {
printf("Username: ");
scanf("%s", username);
printf("Password: ");
scanf("%s", password);
if (strcmp(username, "admin") == 0 && strcmp(password, "password") == 0) {
printf("Welcome, %s!\n", username);
break;
} else {
printf("Invalid username or password. ");
attempts--;
if (attempts > 0) {
printf("You have %d attempt(s) left.\n", attempts);
} else {
printf("You have no more attempts. Goodbye.\n");
}
}
} while (attempts > 0);
return 0;
}
```
In this example, the user is prompted to enter their username and password. The program then checks to see if the username and password match the predefined values (in this case, "admin" and "password"). If the login is successful, the program displays a welcome message. If the login is unsuccessful, the program deducts an attempt and notifies the user of how many attempts they have left. If the user runs out of attempts, the program exits.