3
已解决
猜数游戏:
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main()
{
int count=0;
cout<<"请输入1~99999的数:\n";
srand(time(NULL));
int r=rand()%99999,s;
while(cin>>s&&s!=r)
{
if(s>r)
{
cout<<"太大了!!!"<<endl;
}
else if(s<r)
{
cout<<"太小了!!!"<<endl;
}
count++;
if(count==20)
{
cout<<"很遗憾,你没有猜中!!!正确答案是"<<r;
return 0;
}
}
cout<<"太棒了!!!你猜中了!!!";
return 0;
}
别举报,别举报,千万别举报,求你们了,千万千万别举报
张舒斌在2018-08-14 22:08:53追加了内容
对不起,刚才代码有误,我重新修改的正确代码:
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main()
{
int count=0;
cout<<"请输入1~99999的数:\n";
srand(time(NULL));
int r=rand()%99999,s;
while(cin>>s&&s!=r)
{
if(s>r)
{
cout<<"太大了!!!"<<endl;
}
else if(s<r)
{
cout<<"太小了!!!"<<endl;
}
count++;
if(count==20)
{
cout<<"很遗憾,你没有猜中!!!正确答案是"<<r;
return 0;
}
}
if(s==r)
cout<<"太棒了!!!你猜中了!!!正确答案是:"<<r;
else
{
cout<<"输入错误,游戏结束。";
}
return 0;
}
祝你们游戏愉快
张舒斌在2018-08-15 12:20:23追加了内容
经过徐铭凯的指错和和我的增加,代码终于完成,看:
猜数游戏:
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main()
{
int count=0,ks,js;
cout<<"请输入1~99999的数:\n";
srand(time(NULL));
int r=rand()%99999+1,s;
while(cin>>s&&s!=r)
{
if(s>r)
{
js=s;
cout<<"太大了!!!在"<<js<<"之内"<<endl;
}
else if(s<r)
{
ks=s;
cout<<"太小了!!!在"<<ks<<"之外"<<endl;
}
count++;
if(count==20)
{
cout<<"很遗憾,你没有猜中!!!正确答案是"<<r;
return 0;
}
}
if(s==r)
cout<<"太棒了!!!你猜中了!!!正确答案是:"<<r<<endl<<"你一共猜了"<<count<<"次";
else
cout<<"输入错误,游戏结束。";
return 0;
}
0
0
0
0
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y=-1,tim=0;
srand(time(NULL));
x=rand()%132+75;
cout<<"Please guess:";
while(x!=y)
{
cin>>y;
tim++;
if(y>x) cout<<"too big!"<<endl;
if(y<x) cout<<"too small!"<<endl;
if(y==x) cout<<"OK! ";
}
cout<<x<<" "<<tim<<endl;
return 0;
}
《献给张舒斌》
0
0
0