问题标题: 酷町堂:献上游戏一部(当然,也有蒋智航的功劳)

3
0
已解决
张舒斌
张舒斌
中级光能
中级光能
猜数游戏:
#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
已采纳
周俊豪
周俊豪
高级光能
高级光能

六六六,但是随机性太大,不容易猜中;

猜了将近10遍才猜中;

 

望采纳!

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
徐铭凯
徐铭凯
资深守护
资深守护

等等!有错!是r=rand()%99999+1好不好!

你这个是0~99998!!

0
0
我要回答