Oh man. You guys are life savers! I've been banging my head on this all night. I saw something about casting during a Google search, but it wasn't really clear. I had the syntax all wrong on it, so I scrapped it. I've been messing around with trying to format the number, etc... hell I even spent 30 mins trying to convert everything to a concatenated string!
Whew. That "cast as a different type" thing is exactly what I wanted to do. I just had to round the resulting number, and voila!
Console.WriteLine("Number of Heads: {0} ({1}%).", heads, Math.Round( (heads / (double) numOfTosses) * 100, 2) );
Console.WriteLine("Number of Tails: {0} ({1}%).", tails, Math.Round( (tails / (double) numOfTosses) * 100, 2) );
Thanks again, everyone!
Edit: Though I should probably filter that math through a couple variables so it's easier to read...
double headCount = (heads / (double) numOfTosses) * 100;
double headPercent = Math.Round(headCount, 2);
double tailCount = (tails / (double) numOfTosses) * 100;
double tailPercent = Math.Round(tailCount, 2);
Console.WriteLine("Number of Heads: {0} ({1}%).", heads, headPercent);
Console.WriteLine("Number of Tails: {0} ({1}%).", tails, tailPercent);
Console.WriteLine("");
Last edited by FanIn80; 05-26-2010 at 10:35 PM.
|