Interpreting the last several posts:
Quoted from NT3:
1 2 3 4
|
for (int i = 0; i < iterations; ++i) {
cout << "Please type in first name, last name and your hometown: ";
input(v);
}
|
Assign iteration a value equal to the number of inputs you would like to enter.
Quote from NT3:
1 2 3 4
|
//In that case, use std::random_shuffle from algorithm:
std::random_shuffle(v.begin(), v.end());
std::cout << "Your list: " << std::endl;
print(v);
|
Use the above logic to shuffle your vector before outputting it.
Quote from Catfish666:
1 2
|
//so somewhere we should call:
std::srand(std::time(NULL));
|
Ensure to declare this before std::random_shuffle, though it may not be necessary.
Possibly something like this (credit to the above appropriate programmers):
1 2 3 4 5 6 7 8
|
std::srand(std::time(NULL));
for (int i = 0; i < iterations; ++i) {
cout << "Please type in first name, last name and your hometown: ";
input(v);
}
std::random_shuffle(v.begin(), v.end());
std::cout << "Your list: " << std::endl;
print(v);
|
I believe srand requires the cstdlib.
As for your escape sequence, possibly parse your inputs against "Ctrl -D"?
Ctrl-D is character 'EOT'.
When should the user be able to exit data entry process? (first, last, town, all, or possibly during the control loop)
Maybe a do-while loop instead of a for-loop if you want a user control loop?
1 2 3 4 5 6 7
|
char choice;
do
{
//process code here;
//may need a cin.get() here if cin is flagged.
choice=cin.get();
}while(choice!='EOT');
|
Possible end result:
1 2 3 4 5 6 7 8 9 10 11 12
|
char choice;
std::srand(std::time(NULL));
do
{
cout << "Please type in first name, last name and your hometown: ";
input(v);
//cin.get(); //may need to clear buffer in cin
choice=cin.get();
}while(choice!='EOT');
std::random_shuffle(v.begin(), v.end());
std::cout << "Your list: " << std::endl;
print(v);
|
There are lots of design possibility.
References to Ctrl-D ASCII:
http://www.asciitable.com/
http://www.unix-manuals.com/refs/misc/ascii-table.html
Reference to cin.get():
http://www.cplusplus.com/reference/istream/istream/get/
Note: I have not tested any of the above code, again credits to NT3 and Catfish666.