新人做的小游戏
大神勿喷#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
using namespace std;
int main(void)
{
int n,num,count=1,i=10,u=0;
string mystring;
cout<<"选择难度:"<<"easy,hard,very hard,impossible"<<"\n" ;
cin>>mystring;
if(mystring == "easy")
num=rand()%100;
if(mystring == "hard");
num=rand()%1000;
if(mystring == "very hard")
num=rand()%5000;
if(mystring == "impossible")
{
num=rand()%10000;
for(i=10;i>0;u++,i--)
{
cout<<"猜一个数"<<"\n"<<"还剩"<<i<<"次机会。"<<"\n";
cin>>n;
if(n == num)
break;
else if(n>num)
cout<<"大了!"<<"\n"<<"还剩"<<i<<"次机会!"<<"\n"<<"\n"<<"\n";
else
cout<<"小了!"<<"\n"<<"还剩"<<i<<"此机会!"<<"\n"<<"\n"<<"\n";
}
cout<<"挑战成功!!!"<<"用了"<<u<<"次机会!";
return 0;
}
do
{
cout<<"猜一个数:";
cin>>n;
if(n == num)
break;
else if(n>num)
cout<<"大了!"<<endl;
else
cout<<"小了!"<<endl;
count++;
}while(true);
cout<<"历经"<<count<<"次,猜对了。"<<endl;
return 0;
}