如何让自己挑一个100以内的数字让计算机来猜

2024-11-26 13:38:32
推荐回答(4个)
回答1:

你说的大概是这个吧?//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(time(0)));//seed random number generator

unsigned int randomnumber=rand();//generat randnumber

int die=(randomnumber % guess)+1;//die is between 1 and guess

do
{
srand(static_cast(time(0)));//seed random number generator

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=有问题,一开始像无限循环一样,好几次,最后计算机还是猜得出来。

回答2:

参考答案: 从善如登,从恶如崩。

回答3:

想法新颖。

回答4:

真心的难呐