Hi, i have got a standing answer in this thread. http://stackoverflow.com/questions/2396203/get-the-count-of-elements-where-candidate-has-won
But i am failing to get the percentage, what am i doing wrong. I have the code below.
var s4 = from can in allCandidates
let noDists= ((from d in root.Elements("Provinces")
select d.Attribute("Province").Value).Distinct()).Count()
let count = (from winner in
(from p in root.Descendants("Province_Data")
let maxVotes = (from c in p.Elements("Candidate")
select c)
.Max(x => ((int)x.Element("votes")))
select (from c in p.Elements("Candidate")
select c).Where(x => ((int)x.Element("votes")) == maxVotes)
.First().Element("name").Value )
where winner == can
select winner).Count()
orderby count descending
select new { Candidate = can, NumberOfProvincesWon = count,Percentage= (count/noDists)*100};
foreach (var d in s4)
Console.WriteLine(" {0}", d.ToString());