求C++ 猜数字游戏的代码然后要求是你初始有XXX的金币然后赢了得金币输了扣金币 直到你猜数字为0为止

 我来答
随纸诗巴皮般05
2013-04-10 · TA获得超过3.4万个赞
知道大有可为答主
回答量:3万
采纳率:0%
帮助的人:4519万
展开全部
#include <iostream>
#include <time.h>
using namespace std;

void PrintChoice()
{
cout << "*******************GUESS---NUMBER**********************" << endl
<< "* L:Low difficult --- numbers from 1 to 10 *" << endl
<< "* M:Middle difficult --- numbers form 1 to 50 *" << endl
<< "* H:High difficult --- numbers form 1 to 100 *" << endl
<< "* Q:Quit from game *" << endl
<< "******************************************************" << endl
<< endl
<< "Please Input Your Choice" << endl;
}
bool GuessNumber(int Secret,int Level)
{
bool IsGuessed = false;
int IGuess = 0;

for( int i = 0; i < 3 ; i++)
{
cout << "Guess the number from 1 to " << Level << "." << endl;
cin >> IGuess;
if(IGuess == Secret)
{
cout << "Congratulation." << endl;
return true;
}
else if(IGuess < Secret)
{
cout << IGuess << "is lower." << endl;
}
else if(IGuess > Secret)
{
cout << IGuess << "is higher." << endl;
}
}
cout << "Only 3 times. The number is " << Secret << "." << endl;
return false;
}
int main()
{
bool IsQuit = false;
int Secret;
bool ValidCammand;
srand(time(NULL));
int Level = 10;
while(!IsQuit)
{
char Choice;
PrintChoice();
cin >> Choice;
ValidCammand = false;
switch(Choice)
{
case 'l':;
case 'L':Secret = rand()% 10 + 1;Level = 10 ;break;
case 'm':;
case 'M':Secret = rand()% 50 + 1;Level = 50 ;break;
case 'h':;
case 'H':Secret = rand()% 100 + 1;Level = 100;break;
case 'q':;
case 'Q':IsQuit=true;break;
default:ValidCammand = true;break;
}
if(!IsQuit && !ValidCammand)
{
GuessNumber(Secret,Level);
}
}
}
希望采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式