string.replace help

I'm having trouble with this problem

Modify secondVerse to play "The Name Game" (a.k.a. "The Banana Song"), by replacing "(Name)" with userName but without the first letter. Ex: if userName = "Katie", the program prints:
Banana-fana fo-fatie!
Note: The song verse may change, such as: Banana-fana fo-f(Name)!!! or Apple-fana fo-f(Name)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;

int main() {
   string secondVerse = "Banana-fana fo-f(Name)!";
   string userName = "Katie";

   userName.erase(userName.begin()); // Removes first char from userName

   secondVerse.replace(15,19,"f"+userName+"!"); //can only change this line
   cout << secondVerse << endl;

   return 0;
}


my output looks like this

(check)Testing Katie
Your output: Banana-fana fo-fatie!

(check)Testing Walter
Your output: Banana-fana fo-falter!

(X)Testing Katie and ending with !!! instead of !
Expected output: Banana-fana fo-fatie!!!
Your output: Banana-fana fo-fatie!

how do i get it to sometimes add !!!
Not clear under what conditions you want to add !!!.

The following code will randomly choose between ! and !!!.

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
26
27
28
29
#include <iostream>
#include <string>
#include <ctime>
using namespace std;

int main() 
{   string secondVerse = "-fana fo-f(Name)!";
    string userName = "Katie";
    string fruit;
    string exclam;
    
    srand (time(NULL));     //  Seed the random number generator
    userName.erase(userName.begin()); 

    //  Randomly choose a fruit
    if (rand() % 2) 
        fruit = "Banana";
    else
        fruit = "Apple";        
    //  Randomly choose number of exclmations        
    if (rand() % 2)         
        exclam = "!!!"; 
    else        
        exclam = "!"; 
    secondVerse.replace(9,19,"f"+userName+exclam);         
    cout << fruit << secondVerse << endl;
    system ("pause");
    return 0;
}


Topic archived. No new replies allowed.