您的位置:首页 > 其它

飛飛(十六)猜数字大小

2016-04-02 16:18 183 查看
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作    者:李飞
*完成日期:2016年 4月 2日
*版 本 号:1.0
*
*问题描述:
*输入描述:输入一个1—1000的数,与随机数比较
*程序输出:输出第几次猜对
*/
#include <iostream>
using namespace std;
#include<ctime>
#include<cstdlib>

int main()
{
int n,m,g=0;
srand((unsigned)time(0));
n=1+rand()%1000;
for(;;)
{
cout<<"please input a number:"<<endl;
cin>>m;
g++;
if(m>n)
{
cout<<"大了"<<endl;
}

else if(m<n)
{
cout<<"小了"<<endl;
}
else
{
cout<<"猜对啦"<<endl<<"一共才对了"<<g<<"次"<<endl;
break;
}
}
return 0;
}
<img src="http://img.blog.csdn.net/20160402161852871?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: