0

What it does is when you answer the first question it gives you your reward and then goes to the next question. The problem with that is when it goes to the next question it doesn't change the question, just the answers. I have tried to add a second question with the right words for the question at the "void Question:askQuestion()" section. Sorry if this doesn't make very much sense.

/*
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;
    }

}
NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Punny
  • 13
  • 6
  • Your `cout << "What does cout do?" << endl;` should be `cout << Question_Text << endl;` – apokryfos Nov 04 '15 at 14:48
  • Avoid magic numbers, i.e. `const int highscore_size=5;int High_Score[highscore_size];` instead of `High_Score[5];`. Later you might want your highscore to grow, then you could use `std::vector` instead of plain arrays – 463035818_is_not_an_ai Nov 04 '15 at 14:49
  • And as we are already on the topic: dont use `using namespace std;` (see e.g. [here](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)). The problem is that in fact `cout` could be anything (including ejecting a cd ;), but to be sure that you refer to the `cout` that you want, you should write `std::cout`. – 463035818_is_not_an_ai Nov 04 '15 at 14:52
  • So type std::cout instead of just cout? Sorry if I'm misunderstanding you, I'm still pretty new to this. ;( – Punny Nov 04 '15 at 14:57
  • @Punny yes, exactly. It is unlikely to encounter a different `cout` than the `std::cout` but it makes sense to use it consistently on all `std::` stuff. In addition to what is discussed in the link, imho it makes code much more readable, because one can immediately see if a function is from `std::` or somewhere else. – 463035818_is_not_an_ai Nov 04 '15 at 15:03
  • Alright, thanks! I'm going to go fix that up right quick. – Punny Nov 04 '15 at 15:06

1 Answers1

1

Your problem is you never change the question in askQuestion. You have the question hardcoded

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

What you should have is

cout << Question_Text << endl;
NathanOliver
  • 171,901
  • 28
  • 288
  • 402