an array to hold 5 randon numbers generated by rand();

ok so i wrote a program that stores 5 random numbers into an int lotto_array.

the output is always 0 0 0 0, it doesnt generate 5 random numbers or at least the array is not printing the numbers. why not?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// fantasy 5 number generator
#include <iostream>
#include <conio.h>
#include <ctime>


using namespace std;

int main()
{
    const int Max_fill=5; // the  requried amount of numbers must play is 5
    srand(static_cast<unsigned int>(time(0)));
    
    
    int Lotto_Array[Max_fill]={0}; // an array to hold 5 random generated numbers 1 -36
    
    for(int i=0; i<Max_fill; i++)//for to initiliaze the array
    {
      Lotto_Array[i]=rand()%36+1;// fill the array with 5 random numbers
    cout << Lotto_Array[i] << " ";
       }
         
      
 
 getch();   
    return 0;
}


ok i changed the [max_fill] to [i]
Last edited on
What does line 19 do exactly? Look closely, now...
i compiled the program on rhel 5 and its giving perfectly 5 random numbers!!!
it gave me this:

1st run:
3 7 1 35 5
2nd run:
3 6 31 10 28

try seeding the srand with clock()
Topic archived. No new replies allowed.