大家看看这个程序,为什么输出的结果一直都在跳,就是重复输出,晃的我眼花
#include <iostream>
using namespace std;
int main()
{
const int size=5;
const int strsize=20;
int i;
char ch;
struct bop
{
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preference;
};
bop array[size]=
{
{"pan san","master","handsome man",3},
{"ren gui shan","baogong tou","lucky boy",0},
{"chengqian","teacher","lao ma",3},
{"xiong pi","rubblish","trash",2},
{"noman","notitle","no bop name",1}
};
cout<<"Benevolent order of programmers report\n";
cout<<"a. display by name\tb. display by title\n";
cout<<"c. display by bopname\td. display by preference\n";
cout<<"q. quit\n";
cout<<"Enter your choice:";
cin>>ch;
while(ch!='q')
{
while(ch=='a' || ch=='b' || ch=='c' || ch=='d')
{
if(ch=='d')
{
for(i=0;i<size;i++)
{
switch(array[i].preference)
{
case 0:cout<<array[i].fullname<<endl;break;
case 1:cout<<array[i].title<<endl;break;
case 2:cout<<array[i].bopname<<endl;break;
}
}
}
else
{
for(i=0;i<size;i++)
{
switch(ch)
{
case 'a':cout<<array[i].fullname<<endl;break;
case 'b':cout<<array[i].title<<endl;break;
case 'c':cout<<array[i].bopname<<endl;break;
}
}
}
}
cout<<"Next choice:";
cin>>ch;
}
cout<<"Bye!\n";
return 0;
}
[此贴子已经被作者于2007-9-23 17:35:56编辑过]