The program should simulate rolling of 2 dice and add the sum of the 2 dice after they are rolled for 3600 times.
Their sum ranges from 2-12. The frequency should be tallied in this order
for eg when sum =2 freq =..
when sum =3 freq =..
etc

This is what I have attempted so far but the same frequency is outputted each time. There is some problem with the program and as i can recall it is from the random number generation but can't get to anywhere.

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main ()
{
		int num1,num2,i,j,freq[11]={0},total;
		for (i=1;i<=36000;i++) {
			srand(time(NULL));
			num1=1+rand()%6;
			srand(time(NULL));
			num2=1+rand()%6;
			total=num1+num2;
			freq[total-2]++;
		}
		for(j=2;j<=12;j++)
		{
			printf("%d = %d\n",j,freq[i-2]);
		}
	   fflush(stdin);
	   getchar();
	   return 0;
}

srand() must be called only once -- at the beginning of the program.

srand() must be called only once -- at the beginning of the program.

That's how I did it at first, but the program still is not showing random numbers, even when I arrange that.

printf("%d = %d\n",j,freq[i-2]);

why are you using you using freq[35998]?
I think that integer i your using is supposed to be j.

Oh that makes all the difference. thanks @zeroliken

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.