Randomization and Vectors

Hello,

I would like to know how it is possible for me to do the following:
1)Enter at least 5 words (I am using strings)
2)Store them in a vector
3)Make another vector that stores randomly between 1 to 3 of the words stored in the string.
4)Randomly Shuffles the words.

This is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 #include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){
	srand(time(0));
	string input;
	vector<string>animals;
	cout << "Type Quit to End Game. "<<"Otherwise, Please Enter Animals:"<<endl;
	getline(cin,input);
	animals.push_back(input);
	vector<string>selection(animals);
	random_shuffle (selection.begin(), selection.end());
	for (int i = 0; i < selection.size(); ++i){
		cout << selection[i];
	}

	return 0;
}
1.) Have some constant that defines the minimum number of words required, for example const int min_number_of_words = 5;.

2.) Enter a loop which the user can terminate at any time if they enter some message like "quit" or "exit", however, if they've typed less than min_number_of_words words, they cannot terminate the loop prematurely. Every time they enter a name you push_back() their entry onto a vector of strings (let's call it 'words').
std::vector<std::string> words;
You can check to see how many entries exist in the vector by calling its size() method. Naturally, a "quit" message should not be pushed onto the vector.

3.) Define another variable such as number_of_words and assign to it a pseudo-random number between one and three inclusive.

4.) Shuffle the 'words' vector.

5.) Create another vector of strings, enter a for loop which terminates when a counter variable (let's call it 'n') is less than number_of_words.

6.) For each iteration of the loop, push_back the n'th element from 'words' to our new vector.
Is it okay if I ask of you to elaborate containing the number of words,
i used an if statement
if (animals.size() <= min_input) continue;
I am also having trouble displaying out random shuffle
Topic archived. No new replies allowed.