Hey, this is my first post here, glad to be here and learn from you guys!

what i'm trying to do is this:

I would like to enter 2 names and then hit a number from lets say 1 to 10, and i have the array Q1,Q2... etc. these should be the questions. I want to shuffle them and if I press every time the same number it should give me a another question for another name.

How can I do this? I saw this kind of app on the iphone, and it was fun! But since I'm new to C++, i need some kind of help.
Thank you!

#include <stdlib.h>
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    const int QA = 10;
    string  question[QA] = {"Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", };
    string name1, name2;
    int choice;

    cout << "Enter Name1: ";
    cin >> name1;
    cout << "Enter Name2: ";
    cin >> name2;
    

    system("PAUSE");
    
}

Here's how to use it

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
    const int QA = 10;
    string  question[QA] = {"Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", };
    string name1, name2;
    int choice;

    cout << "Enter Name1: ";
    cin >> name1;
    cout << "Enter Name2: ";
    cin >> name2;
    random_shuffle(&question[0], &question[QA-1]);
    for(int i = 0; i < QA; i++)
        cout << question[i] << '\n';

    system("PAUSE");
    
}

Thanks, my next question is, that how can assign numbers from srand to my questions?

int i;
    srand(time(NULL));
    
    i = rand();

You don't need to use rand/srand if you do what AD showed you. The algorithm takes care of that for itself.

If you want to use the approach you propose there, just do i = rand() % QA; (which will get you a random number between 0 and 9)and cout question.

This article has been dead for over six months. Start a new discussion instead.