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

int main()
{
	int counter,
	number_of_throws = 5,
	threshold = 40;
	
	/* This integer will act as a Boolean, 0 for false, 1 for true. */
	int greater_than_threshold = 0;
	
	/* A simple array. */
	int values[number_of_throws];
	
	/* Initializes random number generator. */
	srand(time(NULL));
	
	/* Store and print number_of_throws random numbers from 0 to 49. */
	for (counter = 0; counter < number_of_throws; counter++) {
		values[counter] = rand() % 50;
		printf("Throw #%d: %02d\n", counter + 1, values[counter]);
		if (values[counter] > threshold) {
			greater_than_threshold = 1;
		}
	}
	
	/* Simple pointer manipulation. */
	int* p = values;
	int sum = 0;
	for (counter = 0; counter < number_of_throws; counter++) {
		sum += *p;
		p++;
	}
	printf("The sum of your throws is %d.\n", sum);
	
	/* If ... else statement. */
	if (greater_than_threshold) {
		printf("You had one throw greater than %d\n", threshold);
	}
	else {
		int new_chance;
		/* While loop. */
		while (!greater_than_threshold) {
			new_chance = rand() % 50;
			if (new_chance > threshold) {
				greater_than_threshold = 1;
				printf("You finally had a throw greater than %d, with %02d!\n", threshold, new_chance);
			}
			else {
				printf("%02d, no luck, let's try again.\n", new_chance);
			}
		}
	}
	return (0);
}