/*
*Copyright(c)2014,烟台大学计算机与控制工程学院
*Allrights reserved.
*文件名称:test.cpp
*作者:肖雪
*完成日期:2016年3月29日
*版本号:v1.0
*
*问题描述:随机产生一个1000内的数字,猜这个整数,如果猜对了,提示猜对了,猜错了提示大了或小了,直到猜对为止
*/
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int x;
x=rand()%1000+1;
srand(time(0));
while(1)
{
int n;
cin>>n;
if(n==x)
{
cout<<"猜测正确"<<endl;
break;
}
else if(n<x)
cout<<"小了"<<endl;
else
cout<<"大了"<<endl;
}
return 0;
}
<img src="https://img-blog.youkuaiyun.com/20160329202910922" alt="" />
第四周 项目3(1)猜数字
