我正在做一个智力竞赛游戏,我很难让第二个问题正常进行
I am making a quiz game, and I am having trouble making the second questio n work properly
它的作用是,当你回答第一个问题时,它会给你奖励,然后转到下一个问题。问题是,当它进入下一个问题时,它不会改变问题,只会改变答案。我试着在"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;
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 等待整个 omp 块完成,然后再调用第二个函数
- 我想在C++中读取一些多个字符,但它永远不会读取第二个字符
- 如何在创建自定义迭代器时获得 std::p air 的第一个和第二个?
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 将第二个 GATT 服务添加到 Movesense 容器
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 比较 2 个向量并从第二个向量中删除在第一个 - c++ 中找不到的元素
- 为什么这个程序没有打印返回的迭代器的正确第二个元素?
- 使第二个类的构造函数成为第一个类中的友元函数
- 为什么第二个代码给出了预期的结果,而第一个代码却没有?
- 为什么第一个代码块产生垃圾值,而第二个代码块将类成员的值相加?
- 打印无序映射的第二个元素,即集合
- 我有一个类,它创建了另一个类的实例.如何将变量通过第一个类传递到第二个类的实例化中?
- 需要使用模板查找数组的第二个最小和最小值
- Google Sparsehash 在类型上使用 realloc(),这很难复制
- c++:交换向量中所有元组的第一个和第二个元素
- 我正在做一个智力竞赛游戏,我很难让第二个问题正常进行
- 很难实现限制每行打印多少个整数