生成c语言代码综合项目功能说明: 程序流程如图 功能模块说明: 1、 登录:密码设置为“abc”,共三次输入密码机会,超过三次为登录不成功。 2、 选择项目:列出三个选项,1、猜数字。2、猜大小。3、退出。选择项目后,执行相应内容。 3、 猜数字:随机产生一个[0,99]间的整数,5次猜数字机会,没猜中会提示太大还是太小。 4、 猜大小:随机产生一个[1,6]间的整数,1-3为小,4-6为大,用户猜大小。 注:猜数字和猜大小模块后,回到选择项目模块。具体效果见执行文件。
时间: 2024-03-16 20:46:07 浏览: 17
以下是生成 C 语言代码的综合项目功能说明:
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
char password[4] = "abc";
char input[4];
int guess;
int answer;
int choice;
int i;
while (1) {
printf("Please enter your password: ");
scanf("%s", input);
if (strcmp(input, password) == 0) {
printf("Login successful!\n");
break;
} else {
printf("Password incorrect, please try again.\n");
i++;
if (i >= 3) {
printf("You have entered the wrong password too many times. Program terminated.\n");
return 0;
}
}
}
while (1) {
printf("Please choose a project:\n");
printf("1. Guess the number\n");
printf("2. Guess the size\n");
printf("3. Quit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
answer = rand() % 100;
for (i = 0; i < 5; i++) {
printf("Please enter your guess (0-99): ");
scanf("%d", &guess);
if (guess < answer) {
printf("Too small!\n");
} else if (guess > answer) {
printf("Too big!\n");
} else {
printf("Congratulations! You've guessed the number!\n");
break;
}
}
break;
case 2:
answer = rand() % 6 + 1;
printf("Please guess the size (1-3 is small, 4-6 is big): ");
scanf("%d", &guess);
if ((guess >= 1 && guess <= 3 && answer >= 1 && answer <= 3) || (guess >= 4 && guess <= 6 && answer >= 4 && answer <= 6)) {
if (guess == answer) {
printf("Congratulations! You guessed it right!\n");
} else {
printf("Sorry, you guessed it wrong.\n");
}
} else {
printf("Invalid input.\n");
}
break;
case 3:
printf("Program terminated.\n");
return 0;
default:
printf("Invalid input.\n");
break;
}
}
return 0;
}
```
这是一个带有登录、选择项目、猜数字和猜大小等模块的 C 语言程序。其中,登录时需要输入密码,超过三次输入错误密码则无法登录。选择项目时有三个选项可供选择,分别是猜数字、猜大小和退出。选择猜数字模块后,程序会随机产生一个 [0,99] 间的整数,用户有 5 次猜数字的机会,如果猜错了会提示是太大还是太小。选择猜大小模块后,程序会随机产生一个 [1,6] 间的整数,其中 1 到 3 为小,4 到 6 为大,用户需要猜大小。需要注意的是,猜数字和猜大小模块执行后会回到选择项目模块。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
![](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)