求C++ 猜数字游戏的代码然后要求是你初始有XXX的金币然后赢了得金币输了扣金币 直到你猜数字为0为止
1个回答
展开全部
#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);
}
}
}
希望采纳
#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);
}
}
}
希望采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询