Strange phenomenon!
Nov 27, 2011 at 12:52pm UTC
I am trying to get a random number that is between 1-10. This is the code that i am using,
1 2 3
int randNum;
randNum = rand() % 10 + 1
cout << randNum;
However, the output of the program was
Anyone could explain that?
Nov 27, 2011 at 12:56pm UTC
Could you post the exact code? I'm guessing there's more to it than what you're showing. Partly because your second line would throw a compile error due to missing ';'.
Nov 27, 2011 at 1:11pm UTC
Hi Gaminic,
Thanks for the prompt reply. I have found the fault.
1 2 3 4 5 6
for (int i=0; i < 5; i++)
{
int randNum;
randNum = rand() % 10 + 1;
cout << randNum;
}
I realized that the for loop was giving me 5 different numbers and I didn't include a endl for my cout. Causing the output of
Topic archived. No new replies allowed.