So here's another update: I've greatly improved the efficiency of the program and have got it working 80% of the time. The other 20% an endless loop occurs. Since this is based on probability, it is likely that my end condition simply isn't met for a very long time, making it appear like an endless loop but not this often. Whatever advice you guys have would be great!
//Yahtzee! VERY basic concept of game with one roll
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int throw1(void)
{
int i_die;
i_die = ( rand() % 6 ) + 1;
return ( i_die );
} //Declaring thow1() function before main()
int main(void)
{
int i_total_rolls = 0;
int i_roll[5]; //Array to store the five dice rolls
int i_yahtzee[5]; //Array used to check status of roll- are all five dice the same?
int i_a, i_b, i_c, i_d, i_e, i_f; //Naming integer variables with i_ prefix to lable them as integers
//variables for for() loops
srand((unsigned)time(NULL)); //Generate seed from clock
do
{
for( i_f = 0; i_f < 5; i_f ++ )
{
i_yahtzee[ i_f ] = 0; //Initialize i_yahtzee array to all zeros so loop doesn't terminate prematurely
}
//Generate dice rolls through throw1() function
for( i_c = 0; i_c < 5; i_c ++ )
{
i_roll[ i_c ] = throw1(); //Call throw1() function and store result in i_roll variable
printf("%d", i_roll[ i_c ]); //TROUBLEHSOOT / Display roll results
}
////////////
putchar('\n');
i_total_rolls ++; //Tally number of attempts
//Check to see if all dice are equal
i_a = 0; //Start comparison at element 0 and compare to all other elements
for( i_b = 1; i_b < 5; i_b ++ ) //compare first die to four subsequent dice
{
if( i_roll[ i_a ] == i_roll[ i_b ] )
{
i_yahtzee[ i_b ] = 1; //If all dice are equal
}
else
{
break; //If dice are not equal, exit comparison loop
}
} //End for() loop
///////////
//TROUBLESHOOT YAHTZEE CHECK RESULTS
for( i_e = 1; i_e < 5; i_e ++ )
{
printf("i_yahtzee[%d] = %d\n", i_e, i_yahtzee[i_e] );
}
//////////////////////
}while( i_yahtzee[4] != 1 ); //Repeat loop until a yahtzee is rolled, indicated by the fifth element of "yahtzee" array being a '1'
printf("total rolls until YAHTZEE: %d\n", i_total_rolls);
//Create border for dice roll display
for( i_d = 0; i_d < 5; i_d ++ )
printf("+---"); //Create a border for results. It is assembled piecewise, according to number of dice rolled
printf("+\n"); //finish border with '+'
//display dice rolls within border
for( i_d = 0; i_d < 5; i_d ++ )
printf("| %d ",i_roll[i_d]); //Display result
printf("|\n");
for( i_d = 0; i_d < 5; i_d ++ )
printf("+---"); //Bottom border created piecewise
printf("+\n");
////////////////////////////
return(0);
}