I'm making an "Identity generator" where the computer randomly picks lines from .txt files.
Although it works fine with the first part of the code, when I repeat that code and change the variables it still uses the old txt file.
Expected result:
Full name: {random first name} {random sur name}
Address: {random address}
Actual result:
Full name: {random first name} {random first name}
Address: {random first name}
My code
cout << "Full name: ";
srand((unsigned) time(NULL));
std::ifstream firstnamefile("englishfirstname.txt");
int total_lines = 0;
while(getline(firstnamefile,line))
{
total_lines++;
lines.push_back(line);
}
int random_number = rand() % total_lines;
cout << lines[random_number] << " ";
//--- Surname ---
srand((unsigned) time(NULL));
std::ifstream surnamefile("englishsurname.txt");
total_lines = 0;
while(getline(surnamefile,line))
{
total_lines++;
lines.push_back(line);
}
random_number = rand() % total_lines;
cout << lines[random_number] << endl;
// --- Address ---
cout << "Address: ";
srand((unsigned) time(NULL));
std::ifstream addressfile("addresses.txt");
total_lines = 0;
while(getline(addressfile,line))
{
total_lines++;
lines.push_back(line);
}
random_number = rand() % total_lines;
cout << lines[random_number] << endl;
The .txt files are just a list of names for example:
John
Michael
Matthew
Etc...