Thread: Help with some array stuff

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    17

    Help with some array stuff

    Basically, 36000 rolls of the dice. I want to output the sum of the two dice (done) the frequency of each sum (done) and the expected along with actual. Both of the later should be in percentage. I know how they would be calculated. Actual is freq/36000 and expected is just stats stuff (1k, 2k, 3k, 4k, 5k, 6k, 5k, 4k, 3k, 2k, 1k).

    When I try to do freq/36000 I just can't get it to work.

    Any suggestions for getting both of these other needed values into arrays and printed?

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    #define SIZE 13
    
    int rollDice(void);
    
    int main ()
    {
    	int roll, sum, freq[SIZE] = {0};
    	float expected[SIZE] = {0}, actual[SIZE] = {0};
    
    	srand(time(NULL));
    
    	for (roll= 1; roll <= 36000; roll++)
    	{
    		sum = rollDice();
    		++freq[sum];
    	}
    	printf("%s%10s%12s%12s\n", "Sum", "Total", "Expected", "Actual");
    
    	for (sum =2; sum <= SIZE -1; sum++)
    	{
    		printf("%2d%10d%12f%12f\n", sum, freq[sum], expected[sum], actual[sum]);
    	}
    	return 0;
    }
    
    int rollDice(void)
    {
       int die1; 
       int die2;   
       int worksum; 
    
       die1 = 1 + ( rand() % 6 ); 
       die2 = 1 + ( rand() % 6 ); 
       worksum = die1 + die2;     
       
       return worksum; 
    }
    Last edited by khskenny; 11-15-2006 at 10:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM