lundi 18 décembre 2017

Generating six digit numbers in C++

I have problem with function that shoud generate six digit numbers. It seems like the program generates the numbers but they allways start with 1. Six digit numbers

And thats part that makes the problem:

void generateNumbers(int &len, int arr[]) {
srand(time(0));
cout << "How many numbers to generate: ";
cin >> len;     
if (len <= 0 || len > 100) {
    cout << "\n Chose number between 1 - 100\n";
    generateNumbers(len, arr);
}
else {

    cout << "\n\nThe numbers: \n";

    for (int i = 0; i < len; i++) {
        arr[i] = (rand() % 999999) + 100000;
        cout << endl << arr[i];

    }
}

}

I know that pobably the rand() % 999999 + 100000 is wrong but i tried differend ways and none of them worked. Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire