Mar 16, 2018 at 4:35pm UTC
I am trying to have string appended to string a number of times using the return function but it isn't working. Here is my code:
string appendTimes(string firstString, string secondString, int integer)
{
for(int i=0; i< integer; i++)
{
return firstString + secondString;
}
}
It should look like, appendTimes( "hello", "there", 2) == "hellotherethre"
but the output is, "hellothere".
We are not supposed to use cout, only return and I have not learned how to use the append function yet, only loops.
Thank you!
Mar 16, 2018 at 5:03pm UTC
Do you realize that when the program encounters a return statement it returns immediately to the calling function anything after the return is not executed?