标题:if镶嵌问题~!
只看楼主
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
 问题点数:0 回复次数:3 
if镶嵌问题~!
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;

class dian
{
public:
    dian();
    void bigen();
    float yaopai();
    void shuchu();
    void dshuchu();
    void shuchu1();
    float fanhui();
private:
    float zong;
    int sheng;
    int s;
    int a1[10];
    int a2[10];
    vector<float> ivec;
};
 
dian::dian()
{
        zong=0;
        sheng=500;
        s=1;
    ivec.push_back(0.5);
    ivec.push_back(1);
    ivec.push_back(2);
    ivec.push_back(3);
    ivec.push_back(4);
    ivec.push_back(5);
    ivec.push_back(6);
    ivec.push_back(7);
    ivec.push_back(8);
    ivec.push_back(9);
    ivec.push_back(10);
}
void dian::bigen()
{
    int k;
    srand( (unsigned)time( NULL ) );
    k=rand()%10;
    if (k<10)
    {
    zong=ivec[k]+ivec[k+1];
    a1[0]=ivec[k];
    a1[1]=ivec[k+1];
    }
    else
    {
    zong=ivec[k]+ivec[k+1];
    a1[0]=ivec[k];
    a1[1]=ivec[k+1];
    }
}
float dian::yaopai()
{
    int k;
    srand( (unsigned)time( NULL ) );
    k=rand()%10;
    zong=zong+ivec[k];
    a1[s];
    ++s;
    return zong;
}
void dian::shuchu()
{
    cout<<"你牌的点数是:";
    for (int i=0;i<=s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
void dian::dshuchu()
{
    cout<<"电脑第二张牌开始的点数是:";
    for (int i=1;i<=s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong-a1[0]<<"点";
    cout<<endl;
}
void dian::shuchu1()
{
    cout<<"电脑的点数是:";
    for (int i=0;i<=s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
float dian::fanhui()
{
    return zong;
}
void guochen(dian &ren,dian &nao)
{
    ren.bigen();
    nao.bigen();
    nao.dshuchu();
    ren.shuchu();
    char a;
    cout<<"要牌输入y否则输入n:";
    cin>>a;
    if (a=='n'||a=='N')
    {
        int s=ren.fanhui();
        int s1=nao.fanhui();
        if (s>s1)       //为什么不管怎么样都进不到这个选择里?
        {
            nao.shuchu1();
            ren.shuchu();
            cout<<"你赢了~!"<<endl;
        }
    }
}

int main()
{
    dian ren,nao;
    guochen(ren,nao);
}
搜索更多相关主题的帖子: private include public sheng 
2010-08-23 22:41
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
得分:0 
...我知道什么问题呢- -  随机函数都是一样的- - 进不到那个循环
    但是不知道怎么改   哪位大哥能教下
2010-08-24 02:26
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
得分:0 
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;

class dian
{
public:
    dian();
    void rule();
    void bigen();
    float yaopai();
    void shuchu();
    void dshuchu();
    void shuchu1();
    float fanhui();
private:
    float zong;
    int s;
    float a1[10];
    vector<float> ivec;
};
 
dian::dian()
{
        zong=0;
        s=2;
    ivec.push_back(0.5);
    ivec.push_back(1);
    ivec.push_back(2);
    ivec.push_back(3);
    ivec.push_back(4);
    ivec.push_back(5);
    ivec.push_back(6);
    ivec.push_back(7);
    ivec.push_back(8);
    ivec.push_back(9);
    ivec.push_back(10);
}
void dian::rule()                                                               //游戏规则            
{
cout<<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"   welcome to 21点 game~!\n";
cout<<"   game rules:\n";
cout<<" 1.庄家 :本轮坐庄的玩家既是计算机.\n";
cout<<" 3.闲家 :本轮不坐庄的玩家。 \n";
cout<<" 4.如果玩家的点数大于21点时点,玩家将不能再要牌;\n";
cout<<" 5.当牌中出现A时,按11点计算,如果总点数大于21点则按1点计算;\n";  
cout<<" 7.如果玩家和电脑同时爆点或者点数相同系统判定为和局!\n";
cout<<" 8.good luck to you!"<<endl;
cout<<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
}
void dian::bigen()
{
    int k,c;
    k=rand()%10;
    srand((unsigned)time(NULL));
    c=rand()%10;
    if (k<10)
    {
    zong=ivec[k]+ivec[c];
    a1[0]=ivec[k];
    a1[1]=ivec[c];
    }
    else
    {
    zong=ivec[k]+ivec[c];
    a1[0]=ivec[k];
    a1[1]=ivec[c];
    }
}
float dian::yaopai()
{
    int k;
    k=rand()%10;
    zong=zong+ivec[k];
    a1[s]=ivec[k];
    s=++s;
    return zong;
}
void dian::shuchu()
{
    cout<<"你牌的点数是:";
    for (int i=0;i<s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
void dian::dshuchu()
{
    cout<<"电脑第二张牌开始的点数是:";
    for (int i=1;i<s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong-a1[0]<<"点";
    cout<<endl;
}
void dian::shuchu1()
{
    cout<<"电脑的点数是:";
    for (int i=0;i<s;++i)
    {
        cout<<a1[i]<<"\t";
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
float dian::fanhui()
{
    return zong;
}
void guochen(dian &ren,dian &nao)
{
    nao.bigen();
    nao.dshuchu();
    ren.bigen();
    ren.shuchu();
    char a;
    cout<<"要牌请输入y否则输入N:";
    cin>>a;
    do
    {
        if(a=='y'||a=='Y')
        {
            ren.yaopai();
            if (nao.fanhui()<16)
            {
                nao.yaopai();
            }
            if (ren.fanhui()>21)
            {
                nao.shuchu1();
                ren.shuchu();
                cout<<"你撑死呢~!"<<endl;
                break;
            }
            if (nao.fanhui()>21)
            {
                nao.shuchu1();
                ren.shuchu();
                cout<<"电脑撑死呢恭喜你赢了~!"<<endl;
                break;
            }
            else
            {
                nao.dshuchu();
                ren.shuchu();
            }
        }
        else if (a=='n'||a=='N')
        {
            if (ren.fanhui()>nao.fanhui())
            {
                nao.shuchu1();
                ren.shuchu();
                cout<<"恭喜你赢了~!"<<endl;
                break;
            }
            else if (ren.fanhui()==nao.fanhui())
            {
                nao.shuchu1();
                ren.shuchu();
                cout<<"平局了~!"<<endl;
                break;
            }
            else
            {
                nao.shuchu1();
                ren.shuchu();
                cout<<"你输呢~!"<<endl;
                break;
            }
        }
        cout<<"要牌请输入y否则输入N:";
        cin>>a;
    }while (a=='y'||a=='Y'||a=='n'||a=='N');
}

int main()
{
    srand((unsigned)time(NULL));
    dian ren,nao;
    ren.rule();
    guochen(ren,nao);
    cout<<"还要继续玩请输入Y:";
    char a;
    cin>>a;
    while (a=='y'||a=='Y')
    {
        srand((unsigned)time(NULL));
        dian ren,nao;
        ren.rule();
        guochen(ren,nao);
        cout<<"还要继续玩请输入Y:";
        cin>>a;
    }

}
 
 
自己顶起- -~!  问题终于解决呢
2010-08-24 05:05
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
得分:0 
代码够长的,不过能解决就好~~
2010-08-24 14:14



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




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

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