Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 31.8k

How to read a Temperature for August and get the total Aveg

May 8 2019 3:49 AM
Hi there
 
How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ?
 
i want to get the Aveg Temperature of August which has 31 day but sometime there is a data of temp just for 29 or 27 however how could i get the Avag based on how many days has been read and saved as data that could be (29,27,26 or 10 days) ?
 
here is the code :
  1. public static TheWeather GetAverageForMonth(List<TheWeather> entries, int year, int month)  
  2. {  
  3. if (entries == null || entries.Count < 1)  
  4. return null;  
  5. int days = 0;  
  6. int index = entries.Count();  
  7. double total = 0.0;  
  8. double Aveg = 0.0;  
  9. for (index = 0; index < entries.Count; index++)  
  10. {  
  11. if (entries[index].dateTime.Year == year && entries[index].dateTime.Month == month)  
  12. {  
  13. total += entries[index].Actual_mean_temp;  
  14. days = entries[index].dateTime.Day;  
  15. }  
  16. }  
  17. Aveg = total / days;  
  18. return entries[index];

Answers (3)