level 6
Lion1942
楼主
如下代码,在要求输入判断字符ch时,程式自动将ch赋值为112 'p',直接跳过,请教下各位原因!
carton* carton::createlist()
{
carton* head=NULL;
carton* end=head;
carton* pstr;
char ch=0;
cout<<"Please input a mentral about a carton!"<<endl;
do{
double heightvalue=0,lengthvalue=0,widethvalue=0;
cin>>heightvalue>>lengthvalue>>widethvalue;
string* mentral=new string;
getline(cin,*mentral);
pstr=new carton(heightvalue,lengthvalue,widethvalue,*mentral);
if(head==NULL)
head=pstr;
else
end->next=pstr;
end=pstr;
cout<<"Do you want to input again?"<<endl;
cin>>ch; ////////此处出现错误
}while(tolower(ch)=='y');
end->next=NULL;
phead=head;
return head;
};
2011年04月22日 14点04分
1
carton* carton::createlist()
{
carton* head=NULL;
carton* end=head;
carton* pstr;
char ch=0;
cout<<"Please input a mentral about a carton!"<<endl;
do{
double heightvalue=0,lengthvalue=0,widethvalue=0;
cin>>heightvalue>>lengthvalue>>widethvalue;
string* mentral=new string;
getline(cin,*mentral);
pstr=new carton(heightvalue,lengthvalue,widethvalue,*mentral);
if(head==NULL)
head=pstr;
else
end->next=pstr;
end=pstr;
cout<<"Do you want to input again?"<<endl;
cin>>ch; ////////此处出现错误
}while(tolower(ch)=='y');
end->next=NULL;
phead=head;
return head;
};