gpt4 book ai didi

c++ - 我正在制作一个问答游戏,但我无法让第二个问题正常工作

转载 作者:行者123 更新时间:2023-11-28 05:59:40 25 4
gpt4 key购买 nike

它的作用是,当您回答第一个问题时,它会给您奖励,然后转到下一个问题。这样做的问题是,当它转到下一个问题时,它不会改变问题,只会改变答案。我试图在“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;

关于c++ - 我正在制作一个问答游戏,但我无法让第二个问题正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33524678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com