第三周练习 随机函数应用于游戏-猜数字
2016-03-23 20:10
302 查看
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述: 随机出10道+-*/计算题
*输入描述:输入答案
*程序输出:输出成绩
*/
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述:猜数字
*输入描述:输入数字
*程序输出:提示正误
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int f,count=0,q,p;
srand(1000);
while(1)
{
f=0;
q=1+rand()%99;
cout<<"请输入数字:"<<endl;
cin>>p;
count++;
if(q==p)
{
cout<<"正确,您一共猜了"<<count<<"次!"<<endl;
f=1;
break;
}
else
{
cout<<"猜错了,加油。你还有"<<10-count<<"次机会"<<endl;
}
if(count==10)
break;
}
if(f==0)
cout<<"很遗憾,你输了。正确数字为"<<q<<endl;
}
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述: 随机出10道+-*/计算题
*输入描述:输入答案
*程序输出:输出成绩
*/
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述: 随机出10道+-*/计算题
*输入描述:输入答案
*程序输出:输出成绩
*/
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述:猜数字
*输入描述:输入数字
*程序输出:提示正误
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int f,count=0,q,p;
srand(1000);
while(1)
{
f=0;
q=1+rand()%99;
cout<<"请输入数字:"<<endl;
cin>>p;
count++;
if(q==p)
{
cout<<"正确,您一共猜了"<<count<<"次!"<<endl;
f=1;
break;
}
else
{
cout<<"猜错了,加油。你还有"<<10-count<<"次机会"<<endl;
}
if(count==10)
break;
}
if(f==0)
cout<<"很遗憾,你输了。正确数字为"<<q<<endl;
}
/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述: 随机出10道+-*/计算题
*输入描述:输入答案
*程序输出:输出成绩
*/
相关文章推荐
- 51nod 1163 (贪心+优先队列)
- Fiddler2中文乱码问题
- FAT32文件系统--For TF卡
- Android FragmentActivity onActivityResult冲突问题
- 从原型链看DOM--Node类型
- 优先级队列的实现 和 层次遍历建树
- 分页式存储管理及地址转换(网易笔试题)
- lintcode:单词切分
- 利用MATLAB绘制隐函数f(x,y)=x^2 * sin(x+y^2)+y^2 * exp(x+y)+5 * cos(x^2+y)=0的曲线
- 通过angularjs的directive以及service来实现的列表页加载排序分页(转)
- 1040. Longest Symmetric String (25)
- Xamarin devexpress datagrid 样式
- linux tar文件解压
- WebView完全解读
- apache配置静态缓存
- imageview wrap_content
- android CheckBox控件的定义及事件监听
- 设计模式之享元模式
- kafka不消费
- Anaconda安装theano出现错误