完善以前写的一个代码,真正实现随机数的生成
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int b;
srand((unsigned)time(NULL));
int a=rand()%100;
do
{
cout<<"请猜一个1~100之间的数:"<<endl;
cin>>b;
if(b>a)
{cout<<"大了,再来"<<endl;}
else if(b<a)
{cout<<"小了,再来"<<endl;}
else
{
cout<<"恭喜你,答对了!!"<<endl;
a=rand()%100;
}
}
while(1);
}
Posted in : by : YullinJuly 18, 20082 CommentsTag : 游戏, 代码, 完善, Ubuntu Linux