猜数字小游戏,很naive......

时间:2022-03-19 16:48:11

这里用到了随机数生成器以及ctime

 #include <cstdio>
#include <cstdlib>
#include <ctime>
#include <windows.h>
using namespace std;
int main()
{
int mo;
printf("Please write the upper limit:");
scanf("%d",&mo);
srand((unsigned)(time(NULL)));
printf("Guess!\n");
while()
{
int n=(rand()%mo)+;
int m,k=;
while(scanf("%d",&m))
{
k++;
if(m==n)
{
printf("Right!You have guessed %d times,too young,too simple,sometimes naive!\n",k);
break;
}
if(m>n) printf("Too large!\n");
else printf("Too small!\n");
}
printf("\nAgain!\n");
}
return ;
}

代码如下: