当前位置:编程学习 > C/C++ >>

高手来解决、C++哪里错了


#include<iostream.h>
#include<stdlib.h>
#include<time.h>
class War
{
private:
int player,comp,bet; //游戏玩家,电脑的两张牌,加注点数
static int nWin,nLost,nDraw; //胜,输,平的局数
static int Loop; //玩家玩的局数
public:
int checkscores();
int c;
static int Score; //玩家的分数
War();
int PLAYER(); //返回player的值
int COMP(); //返回comp的值
void SetCard(); //随机发出两张牌
void Show(int a); //显示所得牌的点数
void Judge(int&); //电脑可以根据自己所得牌面点数的大小判断是否加


static int Scores(int); //一局游戏结束后的分数
void friend Compare(War&,War&,int&,int y); //判断牌面点数的大小,得出胜负结果并且通过q返

回输或赢的分数
void ShowResult(int); //游戏玩家在一局游戏中得到的分数及总共的分数,

并显示出来
void Tj(); //游戏结束以后统计出的最终结果
};
int War::Score=26,War::nWin=0,War::nLost=0,War::nDraw=0,War::Loop=0;
War::War()
{player=0;comp=0;}
int War::PLAYER()
{return player;}
int War::COMP()
{return comp;}
void War::SetCard()
{player=rand()%13+2;
comp=rand()%13+2;}
void War::Show(int x)
{
int num;
if(x==1)num=player;
else if(x==2)num=comp;
switch(num)
{
case 14:cout<<"A";break;
case 13:cout<<"K";break;
case 12:cout<<"Q";break;
case 11:cout<<"J";break;
default:cout<<num;
}
cout<<'\n';
}
void War::Judge(int&y)
{ y =comp-player;
case 1:
case 2:
case 3:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<1;y=1;cout<<'\n';break;
case 4:
case 5:
case 6:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<2;y=2;cout<<'\n';break;
case 7:
case 8:
case 9:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<3;y=3;cout<<'\n';break;
case 10:
case 11:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<4;y=4;cout<<'\n';break;
case 12:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<5;y=5;cout<<'\n';break;

}
int War::Scores(int q=0)
{
Score+=q;return Score;}
int War::checkscores()
{return Score;
}
void Compare(War&A,War&B,int&q,int y)//判断牌面大小,同时通过q返回输或赢的分数
{
cout<<"*********来看看谁才是赌神********\n";
switch(y)
{case 0:
{
if(A.PLAYER()>A.COMP()){cout<<"good luck,你的牌大!\n";q=1;}


else if(A.PLAYER()==A.COMP())cout<<"双方势均力敌!\n";
else{cout<<"oh,my god,电脑的牌大!\n";q=-1;}
break;
}
default:

{
int i,j,m,n;
i=A.PLAYER()==B.PLAYER();
j=A.COMP()==B.COMP();
m=(A.PLAYER()+B.PLAYER())>(A.COMP()+B.COMP());
n=(A.PLAYER()+B.PLAYER())<(A.COMP()+B.COMP());
if(i&&j)
{if(A.PLAYER()>A.COMP()){cout<<"very good,你的对子大!\n";q=y+1;}
else if(A.PLAYER()<A.COMP()){cout<<"so pity,电脑的对子大!\n";q=-y-1;}
else cout<<"双方平分秋色!\n";}
else if(i==1&&j==0)
{cout<<"good luck,你的对子大!\n";q=y+1;}
else if(j==1&&i==0)
{cout<<"so pity,电脑的对子大!\n";q=-y-1;}
else
{
if(m)
{cout<<"very good,你的牌大!\n";q=y+1;}
else if(n)
{cout<<"so bad,电脑的牌大!\n";q=-y-1;}
else{cout<<"双方势均力敌!\n";}
}
}
}
}
void War::ShowResult(int q) //计算出玩家输,赢,平的局数,给出玩家在当局得到的分数
{
Loop++;
if(q>0) {nWin++;cout<<"此局你赢得"<<q+c<<"分\n";
cout<<"你的分数总计为:"<<Scores(q+c)<<endl;}
if(q==0)nDraw++;
if(q<0) {nLost++;cout<<"此局你输掉"<<-q+c<<"分\n";
cout<<"你的分数总计为:"<<Scores(q-c)<<endl;}

}


void War::Tj()
{
cout<<"\n";
cout<<"-------------------------------\n";
cout<<"你的游戏统计如下:\n"<<endl;
cout<<"游戏一共进行了"<<Loop<<"局\n";
cout<<"你胜了"<<nWin<<"局\n";
cout<<"平"<<nDraw<<"局\n";
cout<<"你输了"<<nLost<<"局\n";
cout<<"你最后的分数为:"<<Scores()<<"\n";
if(Score-26>0)cout<<"你在游戏中赢得:"<<Score-26<<"分\n";
else if(Score-26<0)cout<<"你在游戏中输掉:"<<26-Score<<"分\n";
}
//*****主函数部分
void main()
{
War play1,play2;
int x,y=0,q=0,j=1;
srand(time(NULL));
cout<<endl<<"Go,Go,Go!\n"<<"你拥有的分数是26"<<endl<<"当你的"<<\
"分数为0或52的时候系统将自动结束游戏\n"<<endl;
cout<<"=============^^==========================^^=================\n";
cout<<"游戏第一局\n"<<'\n';
S:play1.SetCard();
cout<<"你的第一张牌是";
play1.Show(1);
cout<<"你是否加注,加注[1](不加[0])\n";
cin>>x;
if(x==1)
{ play1.c=0;
cout<<"输入加注的点数,不得大于5\n";
cin>>play1.c;
cout<<"加注点数:"<<play1.c<<endl;
cout<<"电脑的第一张牌是";
play1.Show(2);
play1.Judge(y);
cout<<"**continue**"<<endl;
play2.SetCard();
cout<<"你的第二张牌是";
play2.Show(1);
cout<<"电脑的第二张牌是";
play2.Show(2);
}
else
{ play1.c=0;
cout<<"你选择了不加注\n";
cout<<"电脑的第一张牌是";
play1.Show(2);
play1.Judge(y);

cout<<"**go on**"<<endl;
play2.SetCard();
cout<<"你的第二张牌是";
play2.Show(1);
cout<<"电脑的第二张牌是";
play2.Show(2);
}
Compare(play1,play2,q,y); //判断牌面的大小,得出结果同时通过q返回输或赢的分数
play1.ShowResult(q); //得到并显示在一局游戏中玩家得到的分数以及总计的分数
int i,m,n,t;
m=play1.checkscores();
n=m-52;
if(n>=0){t=0;}
else if(n<=-52){t=1;}
else {t=2;}
switch(t)
{
case 0:
case 1:cout<<"Game Over\n";break;
case 2:
cout<<"继续[1](退出[0])\n";
cin>>i;
if(i==1)
{
cout<<"=======================================\n";
cout<<"这是第"<<++j<<"局游戏\n"<<'\n';
goto S;
}
}
cout<<endl;
play1.Tj(); //进行统计
}


追问:----------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Error spawning cl.exe显示这个,大哥解决下,我加10分
答案:#include<iostream.h>
#include<stdlib.h>
#include<time.h>
using namespace std;//这里应加名字空间说明
class War
{
private:
int player,comp,bet; //游戏玩家,电脑的两张牌,加注点数
static int nWin,nLost,nDraw; //胜,输,平的局数
static int Loop; //玩家玩的局数
public:
int checkscores();
int c;
static int Score; //玩家的分数
War();
int PLAYER(); //返回player的值
int COMP(); //返回comp的值
void SetCard(); //随机发出两张牌
void Show(int a); //显示所得牌的点数
void Judge(int&); //电脑可以根据自己所得牌面点数的大小判断是否加注
static int Scores(int); //一局游戏结束后的分数
void friend Compare(War&,War&,int&,int y); //判断牌面点数的大小,得出胜负结果并且通过q返回输或赢的分数
void ShowResult(int); //游戏玩家在一局游戏中得到的分数及总共的分数,并显示出来
void Tj(); //游戏结束以后统计出的最终结果
};
int War::Score=26,War::nWin=0,War::nLost=0,War::nDraw=0,War::Loop=0;
War::War()
{player=0;comp=0;}
int War::PLAYER()
{return player;}
int War::COMP()
{return comp;}
void War::SetCard()
{player=rand()%13+2;
comp=rand()%13+2;}
void War::Show(int x)
{
int num;
if(x==1)num=player;
else if(x==2)num=comp;
switch(num)
{
case 14:cout<<"A";break;
case 13:cout<<"K";break;
case 12:cout<<"Q";break;
case 11:cout<<"J";break;
default:cout<<num;
}
cout<<'\n';
}
void War::Judge(int&y)
{ y =comp-player;
switch(y)//这里忘了写
{
case 1:
case 2:
case 3:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<1;y=1;cout<<'\n';break;
case 4:
case 5:
case 6:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<2;y=2;cout<<'\n';break;
case 7:
case 8:
case 9:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<3;y=3;cout<<'\n';break;
case 10:
case 11:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<4;y=4;cout<<'\n';break;
case 12:
cout<<"电脑选择加注\n";
cout<<"加注金额:"<<5;y=5;cout<<'\n';break;
}

}
int War::Scores(int q=0)
{
Score+=q;return Score;}
int War::checkscores()
{return Score;
}
void Compare(War&A,War&B,int&q,int y)//判断牌面大小,同时通过q返回输或赢的分数
{
cout<<"*********来看看谁才是赌神********\n";
switch(y)
{case 0:
{
if(A.PLAYER()>A.COMP()){cout<<"good luck,你的牌大!\n";q=1;}


else if(A.PLAYER()==A.COMP())cout<<"双方势均力敌!\n";
else{cout<<"oh,my god,电脑的牌大!\n";q=-1;}
break;
}
default:

{
int i,j,m,n;
i=A.PLAYER()==B.PLAYER();
j=A.COMP()==B.COMP();
m=(A.PLAYER()+B.PLAYER())>(A.COMP()+B.COMP());
n=(A.PLAYER()+B.PLAYER())<(A.COMP()+B.COMP());
if(i&&j)
{if(A.PLAYER()>A.COMP()){cout<<"very good,你的对子大!\n";q=y+1;}
else if(A.PLAYER()<A.COMP()){cout<<"so pity,电脑的对子大!\n";q=-y-1;}
else cout<<"双方平分秋色!\n";}
else if(i==1&&j==0)
{cout<<"good luck,你的对子大!\n";q=y+1;}
else if(j==1&&i==0)
{cout<<"so pity,电脑的对子大!\n";q=-y-1;}
else
{
if(m)
{cout<<"very good,你的牌大!\n";q=y+1;}
else if(n)
{cout<<"so bad,电脑的牌大!\n";q=-y-1;}
else{cout<<"双方势均力敌!\n";}
}
}
}
}
void War::ShowResult(int q) //计算出玩家输,赢,平的局数,给出玩家在当局得到的分数
{
Loop++;
if(q>0) {nWin++;cout<<"此局你赢得"<<q+c<<"分\n";
cout<<"你的分数总计为:"<<Scores(q+c)<<endl;}
if(q==0)nDraw++;
if(q<0) {nLost++;cout<<"此局你输掉"<<-q+c<<"分\n";
cout<<"你的分数总计为:"<<Scores(q-c)<<endl;}

}


void War::Tj()
{
cout<<"\n";
cout<<"-------------------------------\n";
cout<<"你的游戏统计如下:\n"<<endl;
cout<<"游戏一共进行了"<<Loop<<"局\n";
cout<<"你胜了"<<nWin<<"局\n";
cout<<"平"<<nDraw<<"局\n";
cout<<"你输了"<<nLost<<"局\n";
cout<<"你最后的分数为:"<<Scores()<<"\n";
if(Score-26>0)cout<<"你在游戏中赢得:"<<Score-26<<"分\n";
else if(Score-26<0)cout<<"你在游戏中输掉:"<<26-Score<<"分\n";
}
//*****主函数部分
void main()
{
War play1,play2;
int x,y=0,q=0,j=1;
srand((unsigned int)time(NULL));
cout<<endl<<"Go,Go,Go!\n"<<"你拥有的分数是26"<<endl<<"当你的"<<\
"分数为0或52的时候系统将自动结束游戏\n"<<endl;
cout<<"=============^^==========================^^=================\n";
cout<<"游戏第一局\n"<<'\n';
S:play1.SetCard();
cout<<"你的第一张牌是";
play1.Show(1);
cout<<"你是否加注,加注[1](不加[0])\n";
cin>>x;
if(x==1)
{ play1.c=0;
cout<<"输入加注的点数,不得大于5\n";
cin>>play1.c;
cout<<"加注点数:"<<play1.c<<endl;
cout<<"电脑的第一张牌是";
play1.Show(2);
play1.Judge(y);
cout<<"**continue**"<<endl;
play2.SetCard();
cout<<"你的第二张牌是";
play2.Show(1);
cout<<"电脑的第二张牌是";
play2.Show(2);
}
else
{ play1.c=0;
cout<<"你选择了不加注\n";
cout<<"电脑的第一张牌是";
play1.Show(2);
play1.Judge(y);

cout<<"**go on**"<<endl;
play2.SetCard();
cout<<"你的第二张牌是";
play2.Show(1);
cout<<"电脑的第二张牌是";
play2.Show(2);
}
Compare(play1,play2,q,y); //判断牌面的大小,得出结果同时通过q返回输或赢的分数
play1.ShowResult(q); //得到并显示在一局游戏中玩家得到的分数以及总计的分数
int i,m,n,t;
m=play1.checkscores();
n=m-52;
if(n>=0){t=0;}
else if(n<=-52){t=1;}
else {t=2;}
switch(t)
{
case 0:
case 1:cout<<"Game Over\n";break;
case 2:
cout<<"继续[1](退出[0])\n";
cin>>i;
if(i==1)
{
cout<<"=======================================\n";
cout<<"这是第"<<++j<<"局游戏\n"<<'\n';
goto S;
}
}
cout<<endl;
play1.Tj(); //进行统计
}

//PS: 只检查了语法错误. 如有逻辑问题,请告知

上一个:C语言跟C++有什么不同?
下一个:求200行的C++程序源代码

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,