I want to generate 10 random numbers. but all numbers will be different. so I tried to
use bool first make all false. and each generate, assign that argument with bool
but someting is wrong. because outcome is not correct.
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
void sifirla(bool sayi[]); // making zero
int sayisec(bool sayi[]); // choosing number from random seed
int xx[11]; // random numbers will be assigned to xx array.
int main(int argc, char *argv[])
{
bool sayi[10];
time_t qTime;
time(&qTime);
srand(qTime);
sifirla(sayi);
for (int pp=1;pp<11;pp++)
{
xx[pp]=sayisec(sayi);
cout << pp<<".) "<<xx[pp]<<"\n";
}
system("PAUSE");
return EXIT_SUCCESS;
}
void sifirla(bool sayi[]) // all values will be false....
{
for (int x=0;x<11;x++)
{
sayi[x]=false;
}
}
int sayisec (bool sayi[]) // choose random number between 1-10
{
bool sayii = true;
int secilen_sayi = -5;
do {
secilen_sayi=(rand() %10)+1;
if (!sayi[secilen_sayi])
{
sayii=false;
}
}while (sayii);
return secilen_sayi;
}