// july15ex1.cpp : Defines the entry point for the console application.
//  This program creates random names (chosen from lists of first and 
//  last names) and random weights


#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

int main(int argc, char* argv[])
{     int first, last, wt, num, countit;
	   int jc = 0, jt = 0, sc = 0, st=0, bc=0, bt=0;
	   int first_min, last_min, min=9999;

	   float javg, savg, bavg;

     srand(time(NULL));

	 num = rand() % 46 + 5;   /* choose 5 <= num <= 50  */

	 for (countit=1; countit<= num; countit++)  {

		   first=rand() % 4 + 1;
		   last = rand() % 3 + 1;
           wt = rand() % 244 + 7;

		   switch(first) {
		   case 1: printf("Joe "); break;
		   case 2: printf("Suzy "); break;
		   case 3: printf("Mary "); break;
		   case 4: printf("Sam "); break;   
		   } /* end switch first */

		   switch(last) {
		   case 1: printf("Jones "); jc++; jt+=wt; break;
		   case 2: printf("Smith "); sc++; st+=wt; break;
		   case 3: printf("Bond "); bc++; bt+=wt; break;
		   }/* end switch last */


           printf(" weighs %d pounds \n", wt);


		   if (wt < min) {

                  min = wt;
				  first_min = first;
				  last_min = last;


		   } /* end if wt < min */

	 } /*end for countit */

    printf("\nThere were %d people\n", num);
	if (jc){

		javg = (float) jt / jc;
		printf("The average weight for Jones family = %6.2f\n", javg);


	}  /*end if jc */


	if (sc){

		savg = (float) st / sc; 
		printf("The average weight for Smith family = %6.2f\n", savg);

	}
	if (bc){
		bavg = (float) bt / bc;
		printf("The average weight for Bond family = %6.2f\n", bavg);


	}

	printf("The lightest person was ");
		   switch(first_min) {
		   case 1: printf("Joe "); break;
		   case 2: printf("Suzy "); break;
		   case 3: printf("Mary "); break;
		   case 4: printf("Sam "); break;   
		   } /* end switch first */

		   switch(last_min) {
		   case 1: printf("Jones "); jc++; jt+=wt; break;
		   case 2: printf("Smith "); sc++; st+=wt; break;
		   case 3: printf("Bond "); bc++; bt+=wt; break;
		   }/* end switch last */

	printf("who weighed %d pounds \n", min);


	return 0;
}