Its an issue of integer division.
when you divide an integer by an integer it will return an integer. For example 25/100 will return 0 but 25/100.0 will return 0.25 in most programming languages.
You need to cast the divisor to a float.
Console.WriteLine("Number of Heads: {0} ({1}%).", heads, (heads / (double) numOfTosses) * 100.0);
edit this will work also:
{(heads * 100.0) / numOfTosses},
Last edited by sureLoss; 05-26-2010 at 09:57 PM.
|