65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
const int charsize=20;
const int menber=3;
struct bop{
char fullname[charsize];
char title[charsize];
char bopname[charsize];
int preference;
};
int main()
{
using namespace std;
bop person[menber]=
{
{
"pengchang",
"go away",
"Crius.Zc",
3,
},{
"pengruze",
"come and lat's go",
"Rz",
2,
},{
"unkown",
"i don't know",
"zz",
1,
}
};
cout << "Benevolent Order of Programmers Report\n";
cout << "a. display by name\t b. dispaly by title\n"
"c. display by bopname\t d. display by preference\n"
"q. quit\n";
char ch;
cout<<"Enter you choice :";
while(cin>>ch &&ch !='q' &&ch !='Q')
{
while(!(ch>='a' && ch <='d' || ch>='A' && ch<='D'))
{
while(cin.get() !='\n')
continue;
cout<<"That is not a choice ,Choice again:";
cin>>ch;
}
switch(ch)
{
case'a':
case'A':for(int i=0;i<menber;i++)
cout<<person[i].fullname<<endl;break;
case'b':
case'B':for(int i=0;i<menber;i++)
cout<<person[i].title<<endl;break;
case'c':
case'C':for(int i=0;i<menber;i++)
cout<<person[i].bopname<<endl;break;
case'd':
case'D':for(int i=0;i<menber;i++)
{
switch(person[i].preference)
{
case 0:cout<<person[i].fullname<<endl;break;
case 1:cout<<person[i].title<<endl;break;
case 2:cout<<person[i].bopname<<endl;break;
}
}break;
}
while(cin.get()!='\n')
continue;
cout<<"next choice: ";
cin>>ch;
}
cout<<"bye~!"<<endl;
return 0;
}
while(!(ch>='a' && ch <='d' || ch>='A' && ch <='D'))
{
while(cin.get() !='\n')
continue;
cout < <"That is not a choice ,Choice again:";
cin>>ch;
if(ch=='q'||ch=='Q')//这里加个判断 是不是q然后推出程序
exit(1);
}
#include <iostream>
using namespace std;
const int charsize=20;
const int menber=3;
struct bop{
char fullname[charsize];
char title[charsize];
char bopname[charsize];
int preference;
};
int main(){
bop person[menber]={{"pengchang","go away","Crius.Zc",3},{"pengruze","come and lat's go","Rz",2},{"unkown","i don't know","zz",1}};
cout << "Benevolent Order of Programmers Report\n";
cout << "a. display by name\t b. dispaly by title\n"
"c. display by bopname\t d. display by preference\n"
"q. quit\n";
char ch;
cout<<"Enter you choice :";
cin>>ch;
while(ch !='q' && ch !='Q'){
while(!(ch>='a' && ch <='d' || ch>='A' && ch<='D')){
while(cin.get() !='\n')
continue;
cout<<"That is not a choice ,Choice again:";
cin>>ch;
if(ch=='q' || ch== 'Q') //这里加2行
exit(-1);
}
switch(ch){
case'a':
case'A':for(int i=0;i<menber;i++)
cout<<person[i].fullname<<endl;break;
case'b':
case'B':for(int i=0;i<menber;i++)
cout<<person[i].title<<endl;break;
case'c':
case'C':for(int i=0;i<menber;i++)
cout<<person[i].bopname<<endl;break;
case'd':
case'D':for(int i=0;i<menber;i++)
{
switch(person[i].preference)
{
case 0:cout<<person[i].fullname<<endl;break;
case 1:cout<<person[i].title<<endl;break;
case 2:cout<<person[i].bopname<<endl;break;
}
}break;
}
while(cin.get()!='\n')
continue;
cout<<"next choice: ";
cin>>ch;
}
cout<<"bye~!"<<endl;
return 0;
}
