Hello all! I'm trying to write a program that will cout every two numbers I enter. For example, if I were to enter 34 56 78 12 34 67 they would be output in pairs:
34 56
78 12
34 67
This code simply does nothing, so I'm wondering what I've done wrong! Thank you!
1 2 3 4 5 6 7 8 9 10 11
int entryvariable = 0;
int numberofentries = 0;
vector<int>vector1;
while (cin>>entryvariable)
vector1.push_back(entryvariable);
++numberofentries;
if (numberofentries % 2 == 0)
cout<<vector1[numberofentries - 1] << vector1[numberofentries] << "\n";
while (cin>>entryvariable)
vector1.push_back(entryvariable);
++numberofentries;
if (numberofentries % 2 == 0)
cout<<vector1[numberofentries - 1] << vector1[numberofentries] << "\n";
I think you must have brought the block brackets/curly bractest('{}') for the while loop.
So it would be:
1 2 3 4 5 6 7 8 9 10 11 12 13
int entryvariable = 0;
int numberofentries = 0;
vector<int>vector1;
while (cin>>entryvariable)
{//open it here
vector1.push_back(entryvariable);
++numberofentries;
if (numberofentries % 2 == 0)
cout<<vector1[numberofentries - 1] << vector1[numberofentries] << "\n";
}//and close it here