/*
*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="https://img-blog.youkuaiyun.com/20160402161852871?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />