24jun00

 

 
 
 
 
 
 
 

6/24/00 8:17 PM

/******************************************************************/
/*                                                                */
/*  Assignment 2 from Chapter 8 of 'Learn C Under Windows'        */
/*  "rewrite dice.c, showing the possible rolls using three       */
/*  dice instead of two."  I'm not going to re-write the          */
/*  entire program because it's Saturday, and besides, it's       */
/*  too easy to get away with adapting this old piece of code     */
/*  'dice.c' to do my evil bidding.  I plan to 'cheat' in         */
/*  manner as often as possible during my programming career.     */
/*  Thanks to ----- for teaching me that.                  */
/*                                                                */
/******************************************************************/

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

/***********************/
/* Function Prototypes */
/***********************/ //none of this needs to be changed

int  RollOne( void );
void PrintRolls( int rolls[] );
void PrintX( int howMany );

/****************************************************<  MAIN   >*/
int main( void )
{
 int  rolls[ 19 ];       //change range to 19 (18+1)
 int threeDice, i;       //change 'twoDice' to 'threeDice'

 srand( clock() );

 printf("threeDice.c, adapted from \"dice.c\" by csr 24Jun2000\n");

 for ( i=0; i<=18; i++ )       //change range to 18
  rolls[ i ] = 0;

 for ( i=1; i <= 10000; i++ )  //from 1000 to 10000, just for smoother curves
 {
  threeDice = RollOne() + RollOne() + RollOne(); //add one more '+ RollOne() to make three; change 'twoDice' to 'threeDice'
  ++ rolls[ threeDice ];       //change "twoDice" to 'threeDice'
 }

 PrintRolls( rolls );

 printf("\nbeauty, eh?\n");

 return 0;
}

/***************************************************< ROLL ONE  >*/
int RollOne( void )      //no changes here
{
 return (rand() % 6) + 1;
}

/***************************************************< PRINT ROLLS >*/
void PrintRolls( int rolls[] )
{
 int  i;

 for ( i=3; i<=18; i++ )   //change range of loop from (2-12) to (3-18)
 {
  printf( "%2d (%4d):  ", i, rolls[ i ] ); // (%4d) for newfangled 4-digit numbers
  PrintX( rolls[ i ] / 50 ); //divisor chgd to 50 to accomodate increase of loop length by factor of 10
  printf( "\n" );
 }
}

/****************************************************< PRINT X  >*/
void PrintX( int howMany )   //no changes here
{
 int i;

 for ( i=1; i<=howMany; i++ )
  printf( "x" );
}

but we missed out on the Mermaid Parade (sniff).  It was a nice day out, breezy and sunny.  We slept until 1pm, got up to drink water and pee, then went right back to bed again, awaking once and for all at around six.