Try this:
Code:
//sp
//11/30/04
#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
#include <cstdlib>
#include <ctime>
int main()
{
const int size = 6;
int a[size] = {0,0,0,0,0,0};
int tmp, j;
j = 0;
srand(time(0));
for(int w=1; w<11;w++){
cout <<"For game #"<< setw(3) << w << "=";
for(int i=0;i<size;i++){
tmp = rand()%59 +1;
while(j < size) {
if(a[j] == tmp) { // if number has already been taken
tmp = rand()%59 + 1; // generate new rand
j=0;
}
else {
j++;
}
}
a[i] = tmp;
cout << setw(5) << a[i] <<" ";
}
cout <<endl;
}
cout <<endl;
return 0;
}
Note the inner while loop inside your nested for loop. This loop will check the current contents of your array for a duplicate number - if the number has already been called, the loop will reset and generate a new rand to try again.
I didn't compile this, but it should work just fine. If anything, you should get the general idea. Hope this helps.