How Do I Make this program loop?

#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;

int RandomNumber ()
{
return (rand ()%45);
}


int main (int argc, char *argv[])
{
cout << "Press Enter: ";
cin.get ();

srand (unsigned (time (NULL) ) );

vector<int> myvector (1);
vector<int>::iterator it;

generate (myvector.begin(), myvector.end(), RandomNumber);


for (it=myvector.begin(); it!=myvector.end(); ++it)
cout << " " << *it;
cout << "\nPress Enter:";
cin.get ();

}

How do I make the last part of the code loop? so I could hit enter and have it not exit the console?
put it in a while loop so it would look like this

1
2
3
4
5
6
7
8
while(true)
{
  for (it=myvector.begin(); it!=myvector.end(); ++it)
 cout << " " << *it;
 cout << "\nPress Enter:";
 cin.get ();

}
Last edited on
Thank you. Would i need to add another set of code, for say a unique number in order to get it to select a different number each time?
No, you can just keep track of something. For example, if you wanted your while loop to start with x as 0 and increase every time it goes through then you could have something like this:
[code]
while (1)
{
static int x = 0 //You could also define this outside the loop
//Code here
x++; //increment x
}
Topic archived. No new replies allowed.