Printing message with only 40 characters per line.
hi i'm trying to write a function that prints a message over one or more lines, so no line can have more than 40 characters.
I did try using a for loop so if the line has more than 40 characters is prints the next to a new line, but i don't think it's correct.
any help would be appreciated. thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
void printMessage()
{
string message;;
string print[100];
int size = 0;
char c[40];
int maxchar = 40;
cout << "write message" << endl;
getline(cin,message);
for(maxchar; maxchar!=message.size();maxchar++)
{
cout << message[maxchar];
if(message[maxchar]%40==0)
{
cout << endl;
cout << endl;
}
}
cout << message;
|
1 2 3 4 5 6 7 8 9 10 11 12
|
void printMessage ()
{
string message (120, 'A');
int CharsPerLine = 40;
for (size_t i = 0; i < message.size (); i++)
{
if (i > 0 && i % CharsPerLine == 0)
cout << '\n';
cout << message[i];
}
}
|
Topic archived. No new replies allowed.