Quiz Game

I am doing a quiz program using an array of structures to hold:

1. The Question Category(Char).
2. The Question of that Category(Char).
3. The correct answer (Integer).
4. A number of wrong answers (Integers).

Structure Questions={"Category","Question",Correct Answer,{Wrong Answers}}

I find that it is very easy to find information about Randomly generating numbers, but not for positions of output.

User starts game:

*There are 5 wrong answers to call upon: 2000, 1890, 3000, 5660, 2002*

General Knowledge Question:
What year is it?
A)2003 (the correct answer)
B)2000
C)1890

The next time the user plays the game and sees the question:

General Knowledge Question:
What year is it?
A)3000
B)2000
C)2003 (the correct answer)

So I want it randomly picking out of the list of wrong answers, whilst always showing the correct answer. Also the possible answers should randomly change position in A, B, C.

I want to randomly pick questions also, so that each category is represented once and so that a question isn't repeated a second time (is only shown once).

So, I want to create random positioning of output(the Structure's elements), not trying to generate a random value.

Do I have to use a random function on a pointer?

Any help if you can?

My code:


#include
#include

using namespace std;

typedef struct {
char *Category;
char *Question;
int Correct;
int WrongAnswers[4];
} Quiz;

void ShowQuestions(Quiz &q,int n);

int main()
{

int i;
char Choice;

Quiz Questions[]={
{"Maths","What is 9*9?",81,{2,4,78,56}},
{"General Knowledge","How many points on a compass?",8,{1,3}}
};

do{

for(i=0;i<3;i++)
{
ShowQuestions(Questions[i],i+1);
}

cout<<"Do you wish to play again? [Y or N]";
cin>>Choice;

if (Choice=='n')
{
return 0;
}

}while(Choice=='y');

return 0;
}

void ShowQuestions(Quiz &q,int n)
{
int i;

cout<<q.Category<<n<<":"<<q.Question<<"

";
cout<<q.Correct<<" "<<"
";

for(i=0;i<5;i++)
{

cout<<q.WrongAnswers[i]<<" ";
}

}

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories