随机函数应用于游戏

来源:互联网 发布:足球知乎精华 编辑:程序博客网 时间:2024/05/22 02:07

/*
 *copyright(c) 2014,烟台大学计算机学院
 *All rights reserved
 *文件名称:test.cpp
 *作者:吴雨凡
 *版本:v6.0
 *
 *问题描述:随机函数应用于游戏

 *输入描述:
 *程序输出:判断相关问题
*/

#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main( )
{
    int a,b,i=0;
    srand(time(0));
    a=rand()%1000;
    for(i=0;;i++)
    {
        cin>>b;
        if(b>a)
        cout<<"大了";
        if(b<a)
        cout<<"小了";
        if(b==a)
        break;
    }
    cout<<"猜了"<<i<<"次对了";
    return 0;
}

0 0
原创粉丝点击