#include #include #include enum types { TYP_A_, TYP_P_, TYP_E_, TYP_ww, TYP_C_, TYP_aa, TYP__, TYP_chch, TYP_pp, TYP_Ww, TYP_AA }; char * tostr( enum types type ) { switch( type ) { case TYP_A_: return "A_"; case TYP_P_: return "P_"; case TYP_E_: return "E_"; case TYP_ww: return "ww"; case TYP_C_: return "C_"; case TYP_aa: return "aa"; case TYP__: return "__"; case TYP_chch: return "chch"; case TYP_pp: return "pp"; case TYP_Ww: return "Ww"; case TYP_AA: return "AA"; } } void show_banner( void ) { printf( "This program asks you for color information about a pair\n" ); printf( "of gerbils, then predicts the colors of the offspring.\n" ); printf( " d stands for dominant, r stands for recessive\n" ); printf( " if you don't answer or answer with an illegal value,\n" ); printf( " the non-mutated 'wild color' is taken as the default\n" ); printf( "\nType q at any time to end the program.\n" ); } int main( int argc, char ** argv ) { enum types FBASE, MBASE, FPASTEL, MPASTEL, FTICK, MTICK, FWHITE, MWHITE, FALBINO, MALBINO; char input[ 128 ]; if ( argc != 1 ) { printf( "This program asks you for color information about a pair\n" ); printf( "of gerbils, then predicts the colors of the offspring.\n" ); printf( "It is based on a c-shell script by Sharon Kahn\n" ); exit( -1 ); } show_banner(); /* set up defaults */ FBASE = TYP_A_; MBASE = TYP_A_; /* Agouti */ FPASTEL = TYP_P_; MPASTEL = TYP_P_; /* Dark-Eyed */ FTICK = TYP_E_; MTICK = TYP_E_; /* Ticking normal */ FWHITE = TYP_ww; MWHITE = TYP_ww; /* No white-factoring */ FALBINO = TYP_C_; MALBINO = TYP_C_; /* Not albino */ /* QUERY COLOR OF FEMALE */ /* ======== prompt (Base color) ========== */ printf( "FEMALE: base color [d=Agouti, Cinnamon, or Honey; r=Black or Silver; w=white]: \n" ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input == 'r' ) FBASE = TYP_aa; else if ( *input == 'w' ) { FBASE = TYP__; FPASTEL = TYP__; FWHITE = TYP__; FTICK = TYP__; FALBINO = TYP_chch; goto querymale; } /* ======== prompt ( Pastel? ) ========== */ printf( "FEMALE: eye color [d=Black, r=Red or Pink]: " ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input == 'r' ) { if ( FALBINO == TYP_chch ) { FBASE = TYP__; FPASTEL = TYP__; FWHITE = TYP__; goto querymale; } else FPASTEL = TYP_pp; } /* ======== prompt (White marking) ========== */ printf( "FEMALE: white markings on head or neck?[d=yes, r=no]: " ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input = 'd' ) FWHITE = TYP_Ww; /* QUERY COLOR OF MALE */ querymale: printf( "\n" ); /* ======== prompt (Base color) ========== */ printf( "MALE: base color [d=Agouti, Cinnamon, or Honey; r=Black or Silver; w=white]: " ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input == 'r' ) MBASE = TYP_aa; else if ( *input == 'w' ) { MBASE = TYP__; MPASTEL = TYP__; MWHITE = TYP__; MTICK = TYP__; MALBINO = TYP_chch; goto report; } /*======== prompt (Pastel? ) ==========*/ printf( "MALE: eye color [d=Black, r=Red or Pink]: " ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input == 'r' ) { if ( MALBINO == TYP_chch ) { MBASE = TYP__; MPASTEL = TYP__; MWHITE = TYP__; goto report; } else MPASTEL = TYP_pp; } /*======= prompt (White marking) ==========*/ printf( "MALE: White markings on head or neck?[d=yes, r=no]: " ); fgets( input, 128, stdin ); if ( *input == 'q' ) goto cleanup; else if ( *input == 'd' ) MWHITE = TYP_Ww; /* report colors */ report: printf( "\n" ); printf( "Female is probably: %s%s%s%s\n", tostr( FBASE ), tostr( FPASTEL ), tostr( FALBINO ), tostr( FWHITE )); printf( "Male is probably: %s%s%s%s\n", tostr( MBASE ), tostr( MPASTEL ), tostr( MALBINO ), tostr( MWHITE )); printf( "\n" ); printf( "Expected offspring\n" ); printf( "------------------\n" ); if ( MALBINO == TYP_chch && FALBINO == TYP_chch ) { printf ( "White with ruby or pink eyes.\n" ); } else if ( MALBINO == TYP_chch || FALBINO == TYP_chch ) { printf( "Practically any color is possible.\n" ); } /* Black or Silver */ if ( MBASE == TYP_AA && FBASE == TYP_AA ) { if ( MPASTEL == TYP_P_ || FPASTEL == TYP_P_ ) printf ( "Black, and possibly Silver\n" ); else printf( "Silver\n" ); goto whitespot; } /* at least one parent is Agouti variant */ else { if ( MPASTEL == TYP_P_ || FPASTEL == TYP_P_ ) { printf( "Agouti, and possibly Cinnamon\n" ); printf( "Black & Silver are also possible, depending on recessives\n" ); } else { printf( "Cinnamon\n" ); printf( "Silver is also possible, depending on recessives\n" ); } } /* White-marked */ whitespot: if ( MWHITE == TYP_Ww || FWHITE == TYP_Ww ) { printf( "Some with white markings\n" ); } printf( "You might even see some albino-like colors\n" ); cleanup: printf( "\n" ); printf( "************ bye now! ***************\n" ); return 0; }