I cant figure out why my do while loop is not working

I have tryed to more my i but then it does not compile. Thanks for any help

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
30
31
32
#include <iostream>
#include <string>
using namespace 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: 
I don't understand why it isn't working. I ran it through and when you enter 1 it restarted the loop. One alternative is to do:
1
2
3
do{
  //code
}while(more != 0);


Either way it worked fine for me. Good luck!
Topic archived. No new replies allowed.