标题:新人做的小游戏
取消只看楼主
steve221
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-2-27
结帖率:0
已结贴  问题点数:20 回复次数:0 
新人做的小游戏
大神勿喷

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
using namespace std;
int main(void)
    {
    int n,num,count=1,i=10,u=0;
    string mystring;
    cout<<"选择难度:"<<"easy,hard,very hard,impossible"<<"\n" ;
    cin>>mystring;
    if(mystring == "easy")
    num=rand()%100;
    if(mystring == "hard");
    num=rand()%1000;
    if(mystring == "very hard")
    num=rand()%5000;
    if(mystring == "impossible")
    {
    num=rand()%10000;
    for(i=10;i>0;u++,i--)
        {
            cout<<"猜一个数"<<"\n"<<"还剩"<<i<<"次机会。"<<"\n";
            cin>>n;
            if(n == num)
                break;
            else if(n>num)
            cout<<"大了!"<<"\n"<<"还剩"<<i<<"次机会!"<<"\n"<<"\n"<<"\n";
            else
            cout<<"小了!"<<"\n"<<"还剩"<<i<<"此机会!"<<"\n"<<"\n"<<"\n";   
        }
    cout<<"挑战成功!!!"<<"用了"<<u<<"次机会!";
    return 0;
    }
    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;
}
搜索更多相关主题的帖子: include num cout rand 机会 
2018-02-27 20:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-484890-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.107807 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved