# qustion game

• 11-01-2005
Gardul
qustion game
im making something like jeopardy where you have qustions and such. But what i was wondering how can i do random qustions. and how should I go about making the qustions so they can be read. Dont do it for me, just some hints thats all... chow
• 11-01-2005
Shamino
Try assigning each question a variable, say, if you have 100 questions, number them 1-100... then do a random number between 1-100, return the value you get thru a function, whatever is returned display that question...

just a thought :d
• 11-01-2005
hdragon
I think this should be easy. I would use a 2D array with all the questions in it:
Code:

`char question[number_questions][]={"question".....};`
then use rand function to generate a random value and put it in the question array. :D . You can run it in a do, while loop. Oh, you should write a function that prevent the rand generates a number twice, since you have a do loop. Well it's all up to you
• 11-01-2005
sand_man
I don't know much about the STL but I think a std::map might be a good choice.
• 11-01-2005
Gardul
i really dont know much about 2d arrays. but im sure inm y text book they mention it.. any more ideas or hints.
• 11-01-2005
hdragon
Quote:

Originally Posted by Gardul
i really dont know much about 2d arrays. but im sure inm y text book they mention it.. any more ideas or hints.

2D array is not that hard to understand. Ok, just imagine you need 3 char variables array. Normally, you'll do like this:
Code:

```char a1[]="first"; char a2[]="second"; char a3[]="third";```
Well, it's kinda long to declare like that, how about combine them into one. So we have:
Code:

`char a[3][] = {"first", "second", "third"};`
ta da!!! Now you have a 2D array character. Pretty simple heh.
• 11-01-2005
prog-bman
Or if you are a C++ man. You can use strings which then you could just use a single array.
• 11-01-2005
Gardul
Quote:

Originally Posted by hdragon
2D array is not that hard to understand. Ok, just imagine you need 3 char variables array. Normally, you'll do like this:
Code:

```char a1[]="first"; char a2[]="second"; char a3[]="third";```
Well, it's kinda long to declare like that, how about combine them into one. So we have:
Code:

`char a[3][] = {"first", "second", "third"};`
ta da!!! Now you have a 2D array character. Pretty simple heh.

I just read about that actually... I will have to give that a try. and yes I do use C++ Dev.. i was thinking maybe how boreland is soon.
• 11-01-2005
hdragon
Quote:

Originally Posted by prog-bman
Or if you are a C++ man. You can use strings which then you could just use a single array.

Oh well, yeah, forgot about string. String would be good for this kind of stuff
• 11-02-2005
Gardul
Quote:

Originally Posted by hdragon
2D array is not that hard to understand. Ok, just imagine you need 3 char variables array. Normally, you'll do like this:
Code:

```char a1[]="first"; char a2[]="second"; char a3[]="third";```
Well, it's kinda long to declare like that, how about combine them into one. So we have:
Code:

`char a[3][] = {"first", "second", "third"};`
ta da!!! Now you have a 2D array character. Pretty simple heh.

hmm qustion.. {"frist" } what do i put in the " "? would the qustion actually go in there? or just a number or something to link the qustion later?
• 11-04-2005
hdragon
Well, you can either use fstream to load the data into the array of characters or you just define it where you create the characters:
Put the question into the " " marks, like this:
Code:

`char a[3][] = {"This is question number 1", "This is question number 2", "this is question number 3"};`
So then when you want to call out the first question, you will use:
cout<<a[0];
same thing with the others
• 11-05-2005
Shamino
good idea hdragon