Click here to Skip to main content
14,361,266 members
   

C#

 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Ralf Meier8-May-19 1:26
professionalRalf Meier8-May-19 1:26 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran8-May-19 2:49
memberAbdalla Ben Omran8-May-19 2:49 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Gerry Schmitz8-May-19 7:01
mveGerry Schmitz8-May-19 7:01 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
CPallini8-May-19 0:13
mveCPallini8-May-19 0:13 
QuestionRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Eddy Vluggen8-May-19 0:35
mveEddy Vluggen8-May-19 0:35 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran8-May-19 0:53
memberAbdalla Ben Omran8-May-19 0:53 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Eddy Vluggen8-May-19 1:03
mveEddy Vluggen8-May-19 1:03 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
#realJSOP8-May-19 23:28
mve#realJSOP8-May-19 23:28 
public static TheWeather GetAverageForMonth(List<TheWeather> entries, int year, int month)
{
    if (entries == null || entries.Count < 1)
    {
        return null;
    }
    int days = 0;
    int index = entries.Count();
    double total = 0.0;
    double Aveg = 0.0;

    for (index = 0; index < entries.Count; index++)
    {
        // this is your fix
        if (entries[index].dateTime.Year == year 
            && entries[index].dateTime.Month == month 
            // add this line so that it won't include an item without a value
            && entries[index].Actual_mean_temp > 0)
        {
            total += entries[index].Actual_mean_temp;
            // add the "+" to your operator, and only add 1
            days += 1;
        }
    }

    Aveg = total / days;
    return entries[index];
}


EDIT ==========

Fixed again. Everything was in the first if block, and it shouldn't have been.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013


modified 9-May-19 7:29am.

GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Richard MacCutchan8-May-19 23:55
protectorRichard MacCutchan8-May-19 23:55 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
OriginalGriff9-May-19 1:18
protectorOriginalGriff9-May-19 1:18 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
#realJSOP9-May-19 1:29
mve#realJSOP9-May-19 1:29 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
#realJSOP9-May-19 1:28
mve#realJSOP9-May-19 1:28 
QuestionRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Eddy Vluggen9-May-19 1:48
mveEddy Vluggen9-May-19 1:48 
SuggestionRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Richard Deeming9-May-19 1:51
mveRichard Deeming9-May-19 1:51 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
#realJSOP9-May-19 2:30
mve#realJSOP9-May-19 2:30 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran10-May-19 1:03
memberAbdalla Ben Omran10-May-19 1:03 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran9-May-19 2:13
memberAbdalla Ben Omran9-May-19 2:13 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
#realJSOP9-May-19 2:31
mve#realJSOP9-May-19 2:31 
GeneralRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran9-May-19 23:12
memberAbdalla Ben Omran9-May-19 23:12 
QuestionHow to detect advertisement from a Video File Pin
Member 115186794-May-19 2:40
memberMember 115186794-May-19 2:40 
AnswerRe: How to detect advertisement from a Video File Pin
OriginalGriff4-May-19 2:54
protectorOriginalGriff4-May-19 2:54 
AnswerRe: How to detect advertisement from a Video File Pin
#realJSOP4-May-19 3:39
mve#realJSOP4-May-19 3:39 
GeneralRe: How to detect advertisement from a Video File Pin
OriginalGriff4-May-19 3:44
protectorOriginalGriff4-May-19 3:44 
AnswerRe: How to detect advertisement from a Video File Pin
Gerry Schmitz4-May-19 4:06
mveGerry Schmitz4-May-19 4:06 
QuestionHow to get the Average with No LINQ code ! Pin
Abdalla Ben Omran3-May-19 5:19
memberAbdalla Ben Omran3-May-19 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.