Hi,

Although I have had a few years of experience with C programming, I still consider myself a fairly new user. This is because my debugging skills are primitive and I still can't seem to get around simple errors.

I was writing a code to:
- flip a coin a 1000 times
- display "heads" or "tails" as each flip comes up
- count the result of each flip, and display percentages of heads and tails when its done

Although I initially wrote another code which worked fine, I decided to simplify the code. However, I get a few errors, which I cannot seem to get around.

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

#define FLIPS 1000


int main()
{
	int flips, result;
	int head_count = 0;
	float hpercent, tpercent;

	srand((unsigned)time(NULL));

	for(flips=0; flips<FLIPS; flips++)
	{
		result = rand() % 2;

		if(result)
		{
			head_count += 1;
			printf("Heads ");
		}
		else
			printf("Tails ");
		}
	}
	
	hpercent = ((float)head_count / FLIPS) * 100;   /* The errors start here */
	tpercent = 100.0 - hpercent;

	printf("Heads: %.2f percent \n", hpercent);
	printf("Tails: %.2f percent \n", tpercent);          /* And end here */

	return(0);
}
These are the error messages:
coinflip2.c:32: 'head_count' undeclared here <not in a function>
coinflip2.c:32: initializer element is not a constant
coinflip2.c:32: warning: data definition has no type or storage class
coinflip2.c:33: initializer element is not a constant
coinflip2.c:33: warning: data definition has no type or storage class
coinflip2.c:35: parse error before string constant
coinflip2.c:35: warning: data definition has no type or storage class
coinflip2.c:36: parse error before string constant
coinflip2.c:36: warning: data definition has no type or string constant

If anybody has any suggestions, please feel free to help me out.

Thanks,

Thileepan