#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int more;
//I have doubled the number of \n and endl so the text is easier to read
cout <<"Welcome!!! This program will combine text into one line.\n\n";
//this is for the program loop
do
{
string input, output;
cout <<"Enter in text in groups of four, each followed by hitting the enter key\n\n";
//this loop is to create the string
for (int i=0; i<4; i++)
{
getline(cin, input);
output += input + " ";
}
cout << "Here is you text all in one line:\n\n";
cout << output << endl <<endl;
cout<<"Enter 0 to exit, 1 to continue: \n";
more = 0;
cin>> more;
//this is for the program loop
} while (1==more);
system("PAUSE");
return 0;
}
What error is your compiler giving you? It compiles for me, but the result on a second loop is not working. The second loop may be reading in a newline character left over after the 1 is entered at the cin>>more.
(I entered "one two three four", 1 to continue, and then "five six seven eight", 0 to exit)
Welcome!!! This program will combine text into one line.
Enter in text in groups of four, each followed by hitting the enter key
Here is you text all in one line:
one two three four
Enter 0 to exit, 1 to continue:
Enter in text in groups of four, each followed by hitting the enter key
Here is you text all in one line:
five six seven
Enter 0 to exit, 1 to continue: