c/c++语言开发共享纪念第一次写博客

2019 04 07 第一次写博客就记录最基础的c语言下的利用循环 使用时间戳的猜数字游戏 vs 实现 #define _CRT_SECURE_NO_WARNINGS // vs 下的宏定义 (scanf) #include<stdio.h> #include<stdlib.h> #include< …

2019 04 07

第一次写博客就记录最基础的c语言下的利用循环 使用时间戳的猜数字游戏

vs  实现

#define _crt_secure_no_warnings   //  vs   下的宏定义    (scanf)

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include <time.h>

 

 

 

int menu() {
int choice = 0;
printf(“1,游戏开始n”);
printf(“0,游戏结束n”);
scanf(“%d”, &choice);

return choice;

}
void game() {
//加入时间戳 保证取到随机数
srand((unsigned int)time(0)); //(unsigned int)类型的强制转换

int result = rand() % 100 + 1;//产生随机数0-100
while (1) {
printf(“你要猜的数字n”);
int num = 0;
scanf(“%d”, &num);
if (num > result) {
printf(“高了n”);
}
else if (num < result) {
printf(“低了n”);
}
else {
printf(“恭喜你 猜中了n”);
break;
}
}
}
int main()
{
while (1) {
int choice = menu();
if (choice == 1) {
printf(“游戏开始n”);
game();
}
else {
printf(“good bye n”);
break;
}

 

}
system (“pause”);
return 0;
}

 纪念第一次写博客

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/604360.html

(0)
上一篇 2021年5月12日
下一篇 2021年5月12日

精彩推荐