Click here to Skip to main content
15,991,353 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C
srand ( time(NULL) );
random = rand()%45 + 1 ;


hey guys,

I am using above random function and have kept my numbers limited from 1 to 45 but actually when I print an array loop, it crosses it's limit and prints numbers beyond 45 (which I obviouslt don't want).

The other thing it prints in a sequence e.g. 4 5 6 7 8 9 .... when I used time.h and the next line starts after the end digit number of the line before it.

I am making a program where it prints number between 1 to 45 in each row and randomly not in a sequence.

Sample out I am getting:

05 06 07 08 09
10 11 12 13 14
15 16 17 18 19
. . . . . . . . . .
. . . . . . . . . .
55 56 57 58 59
60 61 62 63 64
etc. etc. etc.

Much appreciate your time and advice in advance
Cheers
Posted
Comments
nv3 10-Jul-12 11:39am    
Please show the complete code of your print loop. I would guess that the mistake is in the print statement.
Salman Ali Hero 11-Jul-12 2:21am    
hi nv3,
Have submitted all my code if you can let me know where I am missing.
Cheers
Richard MacCutchan 10-Jul-12 11:53am    
There is a bug in your program which you failed to show us.
Salman Ali Hero 11-Jul-12 2:21am    
Richard,
program is running fine there is no bug in it and for you to have a look at it, I have provided my code as well.
Richard MacCutchan 11-Jul-12 3:05am    
program is running fine there is no bug in it
Sorry to burst your bubble, but there is a very obvious bug in it. See my answer to your "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900