79.0k views
4 votes
Modify secondverse to play "the name game" (a.k.a. "the banana song", see wikipedia.org), by replacing "(name)" with username but without the first letter. ex: if username = "katie", the program prints:

1 Answer

3 votes
I guess you need to write it using C++, so here's your solution:
int main() { string secondVerse = "Banana-fana fo-f(Name)!"; string userName = "Kattie";
userName.erase(userName.begin());
userName.resize(userName.length()); secondVerse = secondVerse.replace(secondVerse.find("(Name)"),6 ,userName);
cout << secondVerse << endl;

return 0;
}

"userName.erase(userName.begin());" - this one removes first letter of the name.
User Chandrika
by
5.1k points