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);
}