我正在做一个智力竞赛游戏,我很难让第二个问题正常进行

I am making a quiz game, and I am having trouble making the second questio n work properly

本文关键字:很难 第二个 常进行 问题 游戏 一个 智力竞赛      更新时间:2023-10-16

它的作用是,当你回答第一个问题时,它会给你奖励,然后转到下一个问题。问题是,当它进入下一个问题时,它不会改变问题,只会改变答案。我试着在"void question:askQuestion()"部分添加第二个问题,并用正确的单词回答这个问题。很抱歉,如果这没有多大意义。

/*
The Great Quiz Show Game
by
Seth A----
*/
#include <iostream>
#include <string>
using namespace std;
int Guess;
int Winnings;
//Define question class
class Question
{
private:
    string Question_Text;
    string Answer_1;
    string Answer_2;
    string Answer_3;
    string Answer_4;
    int Correct_Answer;
    int Prize_Ammount;
    public
        :void setValues(string, string, string, string, string, int, int);
    void askQuestion();
};

int main()
{
    //declare local variables
    int High_Score[5];
    string High_Score_Name[5];
    //initialize local variable
    High_Score[0] = 25000;
    High_Score[1] = 12000;
    High_Score[2] = 7500;
    High_Score[3] = 4000;
    High_Score[4] = 2000;
    High_Score_Name[0] = "Gweneth";
    High_Score_Name[1] = "Adam";
    High_Score_Name[2] = "Nastasia";
    High_Score_Name[3] = "Nicolas";
    High_Score_Name[4] = "Dani";
    cout << "***********************" << endl;
    cout << "*                     *" << endl;
    cout << "* The Great Quiz Show *" << endl;
    cout << "*                     *" << endl;
    cout << "*         by          *" << endl;
    cout << "*                     *" << endl;
    cout << "*      Seth Alpha     *" << endl;
    cout << "*                     *" << endl;
    cout << "***********************" << endl;
    cout << endl;
    //instances of questions
    Question q1;
    Question q2;
    q1.setValues("What does cout do?",
        "Eject a CD",
        "Send text to the printer",
        "Print text on the screen",
        "Play a sound",
        3,
        2500);
    q2.setValues("What are the two sections in a class?",
        "Public and local",
        "Global and local",
        "Global and private",
        "Public and private",
        4,
        5000);
    //ask questions
    q1.askQuestion();
    q2.askQuestion();
    //print HS list
    cout << "High Score List" << endl;
    cout << endl;
    for (int i = 0; i < 5; i++)
    {
        cout << High_Score[i] << "" << High_Score_Name[i] << endl;
    }
}
void Question::setValues(string q, string a1, string a2, string a3, string a4, int ca, int pa)
{
    Question_Text = q;
    Answer_1 = a1;
    Answer_2 = a2;
    Answer_3 = a3;
    Answer_4 = a4;
    Correct_Answer = ca;
    Prize_Ammount = pa;
}
void Question::askQuestion()
{
    cout << endl;
    cout << "What does cout do?" << endl;
    cout << "1." << Answer_1 << endl;
    cout << "2." << Answer_2 << endl;
    cout << "3." << Answer_3 << endl;
    cout << "4." << Answer_4 << endl;
    cout << endl;
    //ask for guess
    cout << "What is your answer?" << endl;
    cin >> Guess;
    //if correct add Prize_Ammount to Winnings
    if (Guess == Correct_Answer)
    {
        cout << endl;
        cout << "You are correct!" << endl;
        Winnings = Winnings + Prize_Ammount
            ; cout << "You just won $" << Prize_Ammount << "!" << endl;
        cout << "Total winnings: $" << Winnings << endl;
        cout << endl;
    }
    else
    {
        cout << endl;
        cout << "You are not correct" << endl;
        cout << "Total winnings: $" << Winnings << endl;
        cout << endl;
    }
}

您的问题是永远不会更改askQuestion中的问题。你有问题硬编码

cout << "What does cout do?" << endl;

你应该拥有

cout << Question_Text << endl;
相关文章: