0

我用元素和点创建了一个结构testQuestion问题answerQuestion。我还创建了一个连接到结构元素的 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);
    }
}

从这里打电话

  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);
    }
}
4

0 回答 0