| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 517 人关注过本帖
标题:求解~! 程序崩溃的原因
只看楼主 加入收藏
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
收藏
 问题点数:0 回复次数:2 
求解~! 程序崩溃的原因
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;

class dian
{
public:
    dian();
    void getppai();
    void rule();
    void bigen();
    void yaopai();
    void shuchu();
    void dshuchu();
    void shuchu1();
    float fanhui();
private:
    float zong;
    int s;
    float a1[2][10];
    vector<int> ivec;
};
 
dian::dian()
{
        zong=0;
        s=2;;
    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);
    ivec.push_back(11);
    ivec.push_back(12);
    ivec.push_back(13);
}
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.当牌中出现J,Q,K按0.5点计算;\n";  
cout<<" 6.如果玩家和电脑同时爆点或者点数相同系统判定为和局!\n";
cout<<" 7.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()%13;
    a1[1][0]=ivec[k];
    if(a1[1][0]==11)
    {
        a1[2][0]=0.5;
    }
    else if(a1[1][0]==12)
    {
        a1[2][0]=0.5;
    }
    else if (a1[1][0]==13)
    {
        a1[2][0]=0.5;
    }
    else
    {
        a1[2][0]=a1[1][0];
    }
    srand((unsigned)time(NULL));
    c=rand()%13;
    a1[1][1]=ivec[c];
    if(a1[1][1]==11)
    {
        a1[2][1]=0.5;
    }
    else if(a1[1][1]==12)
    {
        a1[2][1]=0.5;
    }
    else if (a1[1][1]==13)
    {
        a1[2][1]=0.5;
    }
    else
    {
        a1[2][1]=a1[1][1];
    }
    zong=a1[2][0]+a1[2][1];
}
void dian::yaopai()
{
    int k;
    k=rand()%13;
    a1[1][s]=ivec[k];
    if(a1[1][s]==11)
    {
        a1[2][s]=0.5;
    }
    else if(a1[1][s]==12)
    {
        a1[2][s]=0.5;
    }
    else if (a1[1][s]==13)
    {
        a1[2][s]=0.5;
    }
    else
    {
        a1[2][s]=a1[1][s];
    }
    zong=zong+a1[2][s];
    cout<<a1[2][s]<<endl<<zong;
    s=++s;
}
void dian::shuchu()
{
    cout<<"你牌的点数是:";
    for (int i=0;i<s;++i)
    {
        if(a1[1][i]==11)
        {
            cout<<"J"<<"\t";
            a1[2][i]=0.5;
        }
        else if(a1[1][i]==12)
        {
            cout<<"Q"<<"\t";
            a1[2][i]=0.5;
        }
        else if (a1[1][i]==13)
        {
            cout<<"K"<<"\t";
            a1[2][i]=0.5;
        }
        else
        {
            a1[2][i]=a1[1][i];
            cout<<a1[2][i]<<"\t";
        }
        zong=zong+a1[2][i];
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
void dian::dshuchu()
{
    cout<<"电脑第二张牌的点数是:";
    for (int i=1;i<s;++i)
    {
        if(a1[1][i]==11)
        {
            cout<<"J"<<"\t";
            a1[2][i]=0.5;
        }
        else if(a1[1][i]==12)
        {
            cout<<"Q"<<"\t";
            a1[2][i]=0.5;
        }
        else if (a1[1][i]==13)
        {
            cout<<"K"<<"\t";
            a1[2][i]=0.5;
        }
        else
        {
            a1[2][i]=a1[1][i];
            cout<<a1[2][i]<<"\t";
        }
        zong=zong+a1[2][i]-a1[2][0];
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}

void dian::shuchu1()
{
    cout<<"电脑的点数是:";
    for (int i=0;i<s;++i)
    {
        if(a1[1][i]==11)
        {
            cout<<"J"<<"\t";
            a1[2][i]=0.5;
        }
        else if(a1[1][i]==12)
        {
            cout<<"Q"<<"\t";
            a1[2][i]=0.5;
        }
        else if (a1[1][i]==13)
        {
            cout<<"K"<<"\t";
            a1[2][i]=0.5;
        }
        else
        {
            a1[2][i]=a1[1][i];
            cout<<a1[i]<<"\t";
        }
        zong=zong+a1[2][i];
    }
    cout<<"一共"<<zong<<"点";
    cout<<endl;
}
float dian::fanhui()
{
    return zong;
}
int main()
{
    dian ren;
    ren.bigen();
    ren.yaopai();
}
搜索更多相关主题的帖子: 求解 
2010-08-24 11:49
mxs810
Rank: 9Rank: 9Rank: 9
来 自:火星
等 级:贵宾
威 望:16
帖 子:234
专家分:1122
注 册:2006-10-19
收藏
得分:0 
设置断点,单步跟踪,找到崩溃的位置,然后再处理问题~~~~
要掌握调试程序的基本方法~~

祝你好运

授人以鱼不如授人以渔
2010-08-24 13:31
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
收藏
得分:0 
谢谢, 我已经找到呢~!
  数组越界了    忘记呢 a1[2][10]  是0开头的  没有2
2010-08-24 16:13
快速回复:求解~! 程序崩溃的原因
数据加载中...
 
   



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

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