dev-c++自带小游戏

这是一个简单的C++代码,实现了一个猜数字游戏。玩家可以选择难度级别,然后尝试猜一个在0到选定最大值之间的随机数。如果玩家猜的数字太大或太小,游戏会给出提示,并减少生命值。玩家有5次机会,如果猜中或者生命用尽,游戏将重新开始。
摘要由CSDN通过智能技术生成

代码如下

#include <iostream>
#include <stdlib.h>
#include <time.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 << "Select difficulty mode:\n"; // the user has to select a difficutly level
    cout << "1 : Easy (0-15)\n";
    cout << "2 : Medium (0-30)\n";
    cout << "3 : Difficult (0-50)\n";
    cout << "or type another key to quit\n";
    c = 30;

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

    switch (c) {
        case '1':
            maxrand = 15;  // the random number will be between 0 and maxrand
      

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值