C++实现猜数游戏(源代码)

本文介绍了一款使用C++编写的猜数游戏。通过详细讲解源代码,帮助读者理解C++的基本语法和流程控制。游戏规则简单,计算机随机生成一个介于1到100之间的数字,玩家尝试猜测,程序会给出提示,直到猜中为止。
摘要由CSDN通过智能技术生成
#include <bits/stdc++.h>
using namespace std;

void Start();
void GetResults();

int i, j, life, maxrand;
char c;

void Start()
{
  i = 0;
  j = 0;
  life = 0;
  maxrand = 6;

  cout << "选一个等级:\n"; // the user has to select a difficutly level
  cout << "1 : 简单 (0-20)\n";
  cout << "2 : 中等 (0-40)\n";
  cout << "3 : 困难 (0-60)\n";
  cout << "来选一个吧!!!\n";
  c = 30;

  cin >> c;                   // read the user's choice
  cout << "\n";

  switch (c)
  {
    case '1':
      maxrand = 20;  // the random number will be between 0 and maxrand
      break;
    case '2':
      maxrand = 40;
      break;
    case '3':
      maxrand = 60;
      break;
    default:
      exit(0);
      break;
  }

  life = 5;         // number of lifes of the player
  srand((unsigned)time(NULL)); /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值