为什么输入一个书名后,输不了数字,而且不停循环?
#include<iostream.h>#define N 100
class Book
{
private:
char* bkName;
int bkNum;
public:
Book()
{
bkName=NULL;
bkNum=0;
}
void bkCreat()
{
cout<<"请输入图书名:";
cin>>bkName;
cout<<"销售数目:";
cin>>bkNum;
}
int GetbkNum()
{
return bkNum;
}
void display()
{
cout<<bkName<<" 销售:"<<bkNum<<endl;
}
};
/////////////////////////////////
class Magazine
{
private:
char* zzName;
int zzNum;
public:
Magazine()
{
zzName=NULL;
zzNum=0;
}
void zzCreat()
{
cout<<"请输入杂志名:"<<endl;
cin>>zzName;
cout<<"销售数目:"<<endl;
cin>>zzNum;
}
int GetzzNum()
{
return zzNum;
}
void display()
{
cout<<zzName<<" 销售:"<<zzNum<<endl;
}
};
//////////////////////////////////
void main()
{
int i_1=0,j_1,t_1=0,i_2=0,j_2,t_2=0,flag=1;
Book book[N];
Magazine magazine[N];
while(flag!=0)
{
cout<<"选择销售书籍的类型:"<<endl;
cout<<"1.表示图书,"<<endl;
cout<<"2.表示杂志,"<<endl;
cout<<"0.结束输入。"<<endl;
cin>>flag;
if(flag==1)
{
cout<<"您选择的是图书的输入。"<<endl;
book[i_1].bkCreat();
i_1++;
}
else if(flag==2)
{
cout<<"您选择的是杂志的输入。"<<endl;
magazine[i_2].zzCreat();
i_2++;
}
else if(flag==0)
{
cout<<"已结束输入。"<<endl;
break;
}
else
{
cout<<"选择有误!!!请重新选择!"<<endl;
}
}
j_1=i_1;
j_2=i_2;
cout<<"销售良好的图书:"<<endl;
for(i_1=0;i_1<=j_1;i_1++)
{
if(book[i_1].GetbkNum()>=500)
{
book[i_1].display();
t_1=1;
}
}
if(t_1==0)
{
cout<<"没有销售良好的图书。"<<endl;
}
cout<<"销售良好的杂志:"<<endl;
/////////////////////
for(i_2=0;i_2<=j_2;i_2++)
{
if(magazine[i_2].GetzzNum()>=2500)
{
magazine[i_2].display();
t_2=1;
}
}
if(t_2==0)
{
cout<<"没有销售良好的杂志。"<<endl;
}
我输入1,按回车,
再输入一个书名,如:huangshikun
就得到下面结果
}