Assigning random words from a text file to each character from an inputed name to create and acronym

  acronym, c++, randomized-algorithm, text-files

So user inputs a name, then the code out puts that name one character at a time.
ex. ‘Ailish’ will output as
An in ln in sn hn

I have a text file with adjectives a-z. I want to assign a random adjective that starts with the same character as each line, to create a random acronym. The problem is I don know how to assign each word to the character and how to output it one character with its corresponding adjectve. Please help I am so bad at coding 🙁 Here is what I have so far:

int main (){

string usersName;
int i;

cout << "Enter your name: " << endl;          

getline(cin, usersName);                //Getting usersName

cout << "You entered the name: " << usersName << endl << endl;      

ifstream file("adjecitves.txt");

vector <std::string> adj;

string input;
while(file >> input )                 
{
    adj.push_back(input);
}

for( i= 0; i < usersName.size(); i++){        
    cout << usersName [i] << 'n';
}

int j= 0;
srand(time(0));
rand();

vector<string> acronym;
for ( i=0; i < adj.size() && adj.size(); i++ ){
    cout << i << endl;

    int r = rand()% 5 + 1;
    string word = adj.at(i);
    if ( word.at(0) == usersName.at(j)  ){
        i+=r;
        acronym.push_back(adj.at(i));
        continue;
    }                         
}

for(int i = 0; i < acronym.size(); ++i){
cout << acronym.at(i) << endl;

}

return 0;

}

Source: Windows Questions C++

LEAVE A COMMENT