How can I random quiz questions in C++?

Have created a quiz game. I need the questions to randomly display when i open the program.


4/16/2019 7:29:25 AM

Coder learner

9 Answers

New Answer


Lucky Bill Your question gives no sense. Please explain.


Lets say you have a string array string arr[100]; which contains all the questions now we generate a number which is less than maximum size srand(time(NULL)); int random = (rand()%100); now get the question with the random index number cout << arr[random]; NOTE:- <cstdlib> is needed for rand() and srand() <ctime> is needed for time()


What exactly do you mean? Randomize the order of certain questions or picking a random question (from an array of questions e.g.)


If you want to choose a question randomly from let's say a vector of questions: You'd use the function rand to generate a random number from 0 to size of your vector minus 1 and use that number for accessing the question. cout << your_vector.at( your_random_number) https://en.cppreference.com/w/cpp/numeric/random/rand


Lucky Bill You can also use cout<<arr[(rand()%100)] ; directly I showed that integer for explanation


You can add your quiz game to SL Code Playground and save it. Other users may find it useful.


Flaming Arrow thanks.. Let me try that out..


Aaron Eberhardt i want to make my quiz program questions to display randomly when i open the program......


Sonic here is the code.. Try out.. https://code.sololearn.com/ceadKrLJjoWh/?ref=app