Problem with random number generator
Hello. I have a problem regarding a random number generator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include "time.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
srand(time(NULL));
int lol[11];
for(int i=0; i<10; i++){
int slumptal = rand()%50;
lol[i]=slumptal;
cout<<lol;
}
return 0;
}
|
This is my code. But when I execute it it only returns 0x28feec.
Why? And how should I correct the code?
line 17 should probably be cout<<lol[i];
lol is an array, and when used with cout<<lol
devolves into a pointer - the address of the array.
Try cout<<lol[i]
to get the actual contents of the array.
Thanks! Newb mistake.
I note also that you've made an array with 11 elements, but you only use 10 of them. Is that deliberate, or a mistake?
Topic archived. No new replies allowed.