c语言程序军营游戏代码,猜数字游戏C语言编程

满意答案

00e27ab806e4881f8254fe7ae8741834.png

guobao554

2014.01.23

00e27ab806e4881f8254fe7ae8741834.png

采纳率:59%    等级:9

已帮助:2116人

#include

#include

#include

using namespace std;

int i, j, life, maxrand;

char c;

void Start ();

void GetResults ();

void Start (){

i = 0;

j = 0;

life = 0;

maxrand = 6;

cout << "Select difficulty mode:\n";

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;

cout << "\n";

switch (c){

case '1' : maxrand = 15;

break;

case '2' : maxrand = 30;

break;

case '3' : maxrand = 50;

break;

default : exit(0);

break;

}

life = 5;

srand( (unsigned)time( NULL ) );

j = rand() % maxrand;

GetResults();

}

void GetResults (){

if (life <= 0){

cout << "You lose !\n\n";

Start();

}

cout << "Type a number: \n";

cin >> i;

if ((i>maxrand) || (i<0)){

cout << "Error : Number not between 0 and \n" << maxrand;

GetResults();

}

if (i == j){

cout << "YOU WIN !\n\n";

Start();

}

else if (i>j){

cout << "Too BIG\n";

life = life - 1;

cout << "Number of remaining life: " << life << "\n\n";

GetResults();

}

else if (i

cout << "Too SMALL\n";

life = life - 1;

cout << "Number of remaining life:\n" << life << "\n\n";

GetResults();

}

}

int main ()

{

cout << "** Jackpot game **\n";

cout << "The goal of this game is to guess a number. You will be ask to type\n";

cout << "a number (you have 5 guess)\n";

cout << "Jackpot will then tell you if this number is too big of too small compared to the secret number to find\n\n";

Start();

return 0;

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值