求一个简单的C++小游戏源程序。有注释。
1个回答
展开全部
#include<iostream>
using namespace std;
#include <time.h>
#include <stdlib.h>
int main()
{
int x;
cout<<"输入任意数字开始。"<<endl; //使用 输入是否为 数字来判断是否继续猜
while(cin>>x)
{
srand((int)time(0));
int m = rand()%100+1;//生成随机数m范围1到100
int i =0,n;
for (;i<10;i++)//判断是否才对,10次为限,i用来计算才对次数
{
cout<<"input the number you guess:"<<endl;
cin>>n;
if( n > m )
cout<<"wrong,too high!"<<endl;
if( n < m )
cout<<"wrong,too low!"<<endl;
if( n == m)
{cout<<"right,and the times you have guessed is"<<i<<"."<<endl;break;}
}
cout<<"输入任意数字继续。"<<endl;
}
system("pause");
return 0;
}
using namespace std;
#include <time.h>
#include <stdlib.h>
int main()
{
int x;
cout<<"输入任意数字开始。"<<endl; //使用 输入是否为 数字来判断是否继续猜
while(cin>>x)
{
srand((int)time(0));
int m = rand()%100+1;//生成随机数m范围1到100
int i =0,n;
for (;i<10;i++)//判断是否才对,10次为限,i用来计算才对次数
{
cout<<"input the number you guess:"<<endl;
cin>>n;
if( n > m )
cout<<"wrong,too high!"<<endl;
if( n < m )
cout<<"wrong,too low!"<<endl;
if( n == m)
{cout<<"right,and the times you have guessed is"<<i<<"."<<endl;break;}
}
cout<<"输入任意数字继续。"<<endl;
}
system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询