猜数字小游戏

简介: 猜数字小游戏
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
  printf("*******************************************\n");
  printf("*********      1.play           ***********\n");
  printf("*********      0.exit           ***********\n");
  printf("*******************************************\n");
}
void game()
{
  int guess = 0;
  int r = rand() % 100 + 1;
  while (1)
  {
    printf("猜数字:>");
    scanf("%d", &guess);
    if (guess < r)
    {
      printf("猜小了\n");
    }
    else if (guess > r)
    {
      printf("猜大了\n");
    }
    else
    {
      printf("恭喜你,猜对了\n");
      break;
    }
  }
}
int main()
{
  int input = 0;
  srand((unsigned int)time(NULL));
  do
  {
    menu();
    printf("请选择:>");
    scanf("%d", &input);
    switch (input)
    {
    case 1:
      game();
      break;
    case 0:
      printf("退出游戏\n");
      break;
    default:
      printf("选择错误\n");
      break;
    }
  } while (input);
  return 0;
}

image.png

相关文章
|
16天前
|
C++
C++小练习:猜数游戏
C++小练习:猜数游戏
|
2月前
|
存储 算法 编译器
捣蛋小游戏——猜数字
捣蛋小游戏——猜数字
26 0
|
2月前
|
C语言
猜数字小游戏(随机生成’三剑客‘)
猜数字小游戏(随机生成’三剑客‘)
|
2月前
|
弹性计算 运维 算法
猜数游戏
【4月更文挑战第29天】
23 1
|
2月前
L1-056 猜数字
L1-056 猜数字
16 0
|
2月前
|
BI
猜数字
猜数字
18 0
|
12月前
猜数字小游戏
猜数字小游戏
45 0
|
11月前
|
存储 C语言
你也能做的简单版猜数字游戏(和优化版猜数字)
你也能做的简单版猜数字游戏(和优化版猜数字)
|
12月前
|
C++
你猜我猜不猜 (猜数字游戏) 快来小玩一把叭
你猜我猜不猜 (猜数字游戏) 快来小玩一把叭
71 0
猜数字小游戏(加强版)它来了
猜数字小游戏(加强版)它来了
59 0