C++写一个交友软件代码
时间: 2023-03-26 22:00:18 浏览: 108
很高兴回答你的问题。以下是一个简单的交友软件的代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_USERS 100
#define MAX_NAME_LENGTH 50
#define MAX_AGE 120
typedef struct {
char name[MAX_NAME_LENGTH];
int age;
char gender;
char interests[100];
} User;
User users[MAX_USERS];
int num_users = ;
void add_user() {
if (num_users >= MAX_USERS) {
printf("Sorry, the maximum number of users has been reached.\n");
return;
}
User new_user;
printf("Enter name: ");
scanf("%s", new_user.name);
printf("Enter age: ");
scanf("%d", &new_user.age);
printf("Enter gender (M/F): ");
scanf(" %c", &new_user.gender);
printf("Enter interests (comma-separated): ");
scanf("%s", new_user.interests);
users[num_users] = new_user;
num_users++;
}
void list_users() {
printf("Name\tAge\tGender\tInterests\n");
for (int i = ; i < num_users; i++) {
printf("%s\t%d\t%c\t%s\n", users[i].name, users[i].age, users[i].gender, users[i].interests);
}
}
int main() {
while (1) {
printf("What would you like to do?\n");
printf("1. Add user\n");
printf("2. List users\n");
printf("3. Quit\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_user();
break;
case 2:
list_users();
break;
case 3:
exit();
default:
printf("Invalid choice.\n");
}
}
return ;
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)