猫武士世界 猜数C++程序
如题
#include<bits/stdc++.h>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
while(1)
{
int s=(rand()*rand())%100000+1;
int num=0;
while(1)
{
int t;
scanf("%d",&t);
int Q=abs(t-s);
if(Q==0)
{
printf("你猜中了数字为%d,获得猜数金叶%d\n",t,num);
break;
}
else
{
printf("你猜的数字为%d,",t);
if(Q<=10)
printf("几乎等于实际数字。");
else
{
if(Q<=100)
printf("稍稍");
else if(Q<=1000)
printf("略");
else if(Q<=5000)
printf("");
else if(Q<=10000)
printf("远");
else
printf("远远");
if(t>s)
printf("大");
else
printf("小");
printf("于实际数字。");
}
printf("当前猜数金叶累计%d。\n此操作消耗1金叶。\n",num);
}
num++;
}
}
}