您的位置:首页 > 其它

第3周项目1 经过几次猜对数字大小

2016-03-17 20:25 405 查看
<pre class="html" name="code">问题及代码 :
/*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称 :
*作    者 : 刘云
*完成日期 : 2016年3月12号
*版 本 号 : v1.0
*
*问题描述 :  猜数字
*输入描述 :  给出随机数,输入所猜的数字的大小
*程序输出 :  答对后猜题的次数
*/
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(void)
{
int n,num,count=1;
srand(time(0));
num=rand()%100;
do
{
cout<<"输入一个数  :   ";
cin>>n;
if(n==num)
break;
else
{
if(n>num)
cout<<"大了"<<endl;
else
cout<<"小了"<<endl;
count++;
}
}while(true);
cout<<"经过"<<count<<"次,终于答对了。"<<endl;
return 0;
}
知识点总结 :
从这个过程中,进一步巩固了对简单程序结构的认识,也学会了计算 c程序方法
学习心得 :
从现在开始,我要认真学习C++,巩固知识点,在这个领域做到最好。



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: