主题:各位高手帮帮忙
#include "stdafx.h"
#include <iostream>
using namespace std;
struct bop
{
char fullname[30];
char title[30];
char bopname[30];
int preference;
};
void show();
void choose(char choice,int num,bop b[]);
int _tmain(int argc, _TCHAR* argv[])
{
int num;
char choice;
cout<<"Please input the number of people ";
cin>>num;
bop*b=new bop[num];
for(int i=0;i<num;i++)
{
cout<<"Fullname: ";
cin.getline(b[i].fullname,30);
cout<<"Title: ";
cin.getline(b[i].title,30);
cout<<"Bopname: ";
cin.getline(b[i].bopname,30);
cout<<"Preference: ";
cin>>b[i].preference;
cout<<endl;
}
show();
cin>>choice;
while(choice!='q')
{
choose(choice,num,b);
cout<<endl;
show();
cin>>choice;
}
cout<<endl;
cout<<"Bye"<<endl;
delete[] b;
return 0;
}
void show()
{
cout<<"Benevolent Order of Programmers Report"<<endl;
cout<<"a. display by name b. display by title"<<endl;
cout<<"c. display by bopname d. display by preference"<<endl;
cout<<"q. quit"<<endl;
cout<<"Enter your choice: ";
}
void choose(char choice,int num,bop b[])
{
switch(choice)
{
case 'a': for(int i=0;i<num;i++)
{
cout<<b[i].fullname<<endl;
}
break;
case 'b': for(int i=0;i<num;i++)
{
cout<<b[i].title<<endl;
}
break;
case 'c': for(int i=0;i<num;i++)
{
cout<<b[i].bopname<<endl;
}
break;
case 'd': for(int i=0;i<num;i++)
{
cout<<b[i].preference<<endl;
}
break;
case 'q': return;
default: cout<<"Input Error"<<endl;
return;
}
}
程序不知道错在哪里?可能是getline的问题
cin.getline(b[i].fullname,30); 这句好像没有执行 因为我都没机会输入
#include <iostream>
using namespace std;
struct bop
{
char fullname[30];
char title[30];
char bopname[30];
int preference;
};
void show();
void choose(char choice,int num,bop b[]);
int _tmain(int argc, _TCHAR* argv[])
{
int num;
char choice;
cout<<"Please input the number of people ";
cin>>num;
bop*b=new bop[num];
for(int i=0;i<num;i++)
{
cout<<"Fullname: ";
cin.getline(b[i].fullname,30);
cout<<"Title: ";
cin.getline(b[i].title,30);
cout<<"Bopname: ";
cin.getline(b[i].bopname,30);
cout<<"Preference: ";
cin>>b[i].preference;
cout<<endl;
}
show();
cin>>choice;
while(choice!='q')
{
choose(choice,num,b);
cout<<endl;
show();
cin>>choice;
}
cout<<endl;
cout<<"Bye"<<endl;
delete[] b;
return 0;
}
void show()
{
cout<<"Benevolent Order of Programmers Report"<<endl;
cout<<"a. display by name b. display by title"<<endl;
cout<<"c. display by bopname d. display by preference"<<endl;
cout<<"q. quit"<<endl;
cout<<"Enter your choice: ";
}
void choose(char choice,int num,bop b[])
{
switch(choice)
{
case 'a': for(int i=0;i<num;i++)
{
cout<<b[i].fullname<<endl;
}
break;
case 'b': for(int i=0;i<num;i++)
{
cout<<b[i].title<<endl;
}
break;
case 'c': for(int i=0;i<num;i++)
{
cout<<b[i].bopname<<endl;
}
break;
case 'd': for(int i=0;i<num;i++)
{
cout<<b[i].preference<<endl;
}
break;
case 'q': return;
default: cout<<"Input Error"<<endl;
return;
}
}
程序不知道错在哪里?可能是getline的问题
cin.getline(b[i].fullname,30); 这句好像没有执行 因为我都没机会输入