你说的大概是这个吧?//Die Roller
//demonstrates generating random numbers
#include
#include
#include
#include
using namespace std;
int main()
{
int guess;
cout<<"\nenter a guess :";
cin>>guess;
srand(static_cast
unsigned int randomnumber=rand();//generat randnumber
int die=(randomnumber % guess)+1;//die is between 1 and guess
do
{
srand(static_cast
unsigned int randomnumber=rand();//generat randnumber
int die=(randomnumber % guess)+1;//die is between 1 and guess
cout<<"die="<
int trise=0;
++trise;
if(guess>die)
{
die+=1;
}
else if(guess
die-=1;
}
else
{cout<<"\nthat's it!"<<"\ndie="<
break;}
}while(die!=guess);
system("pause");
return 0;
}
就是trise=有问题,一开始像无限循环一样,好几次,最后计算机还是猜得出来。
参考答案: 从善如登,从恶如崩。
想法新颖。
真心的难呐