我已经使用元素testQuestion,answerQuestion和point创建了一个结构问题。我还创建了一个void函数,该函数连接到结构的元素。当我调用该函数并输入问题时,程序不会继续到其他元素即答案,而是转回输入用户名和密码。为什么会这样?
```
struct professor
{
string username;
string password;
};
professor professorData;
struct question
{
char testQuestion[50];
char answerQuestion[50];
int pointQuestion;
};
question questionData;
void readProfessor(professor& professorData)
{
cout<<"Enter the professor username: ";
cin>>professorData.username;
cout<<"Enter the professor password: ";
cin>>professorData.password;
cout<<endl;
}
void readQuestion(question& questionData)
{
cout<<"Enter the question: "<<endl;
cin>>questionData.testQuestion;
cout<<"Enter the answers: "<<endl;
cin>>questionData.answerQuestion;
}
void professorMenu()
{
string pUsername;
string pPassword;
cout<<"Enter professor username: ";
cin>>pUsername;
cout<<"Enter professor password: ";
cin>>pPassword;
if((pUsername.compare(professorData.password)==0) && (pPassword.compare(professorData.password)==0))
{
readQuestion(questionData);
}
}
calling from here
adminMenu()
{
int adminUsername = 1234;
int inputAdminUsername;
char adminPassword[6] = "admin";
char inputAdminPassword[6];
int a;
string inputStudent[20];
string inputProfessor[20];
cout<<"Enter admin username: ";
cin>>inputAdminUsername;
cout<<"Enter admin password: ";
cin>>inputAdminPassword;
if(inputAdminUsername == adminUsername && strcmp(adminPassword, inputAdminPassword) == 0)
{
cout<<"Successful login."<<endl;
do
{
cout<<"Press 1 to add professor"<<endl;
cout<<"Press 2 to add student"<<endl;
cout<<"Press 3 to go back to main menu"<<endl;
cin>>a;
if(a==1)
{
readProfessor(professorData);
}
else if (a==2)
{
readStudent(studentData);
}
else if(a==3)
mainMenu();
}
while(a!=3);
}
}