Answer the question
In order to leave comments, you need to log in
How to fill a line with words?
There is some word, for example "home".
It is necessary to fill a string with this word for a certain number of iterations (you can use not strings but a char array)
I tried to throw something in .. but it doesn’t work. the size of the iterations is greater than the characters in the string
string word = "home";
string result = "";
for (int i = 0; i<19i++)
{
result += word[i];
}
Answer the question
In order to leave comments, you need to log in
- Think about what you have here word[4]
- Calculate (find) the end of the line.
- Check the condition (and not the end of the line)
- If yes, then print the characters on a new one.
early please)
for( int i = 0; i < rep; i++ )
result += word[ i % word.length() ];
for( uint i = 0; i < rep; i += word.length() )
result += rep - i > word.length() ? word : word.substr( 0, rep - i );
for( uint i = 0; i < rep / word.length(); i++ )
result += word;
result += word.substr( 0, rep % word.length() );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question