Click here to Skip to main content
15,893,594 members
Home / Discussions / C#
   

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 0:26
mveRalf Meier8-May-19 0: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 1:49
Abdalla Ben Omran8-May-19 1: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 6:01
mveGerry Schmitz8-May-19 6:01 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
CPallini7-May-19 23:13
mveCPallini7-May-19 23:13 
QuestionRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Eddy Vluggen7-May-19 23:35
professionalEddy Vluggen7-May-19 23:35 
AnswerRe: How to read a Temperature for August and get the total Aveg just for 29 day instead 31 day ? Pin
Abdalla Ben Omran7-May-19 23:53
Abdalla Ben Omran7-May-19 23: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 0:03
professionalEddy Vluggen8-May-19 0: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 22:28
mve#realJSOP8-May-19 22:28 
C#
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 22:55
mveRichard MacCutchan8-May-19 22: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 0:18
mveOriginalGriff9-May-19 0: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 0:29
mve#realJSOP9-May-19 0: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 0:28
mve#realJSOP9-May-19 0: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 0:48
professionalEddy Vluggen9-May-19 0: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 0:51
mveRichard Deeming9-May-19 0: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 1:30
mve#realJSOP9-May-19 1: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 0:03
Abdalla Ben Omran10-May-19 0: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 1:13
Abdalla Ben Omran9-May-19 1: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 1:31
mve#realJSOP9-May-19 1: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 22:12
Abdalla Ben Omran9-May-19 22:12 
QuestionHow to detect advertisement from a Video File Pin
Member 115186794-May-19 1:40
Member 115186794-May-19 1:40 
AnswerRe: How to detect advertisement from a Video File Pin
OriginalGriff4-May-19 1:54
mveOriginalGriff4-May-19 1:54 
AnswerRe: How to detect advertisement from a Video File Pin
#realJSOP4-May-19 2:39
mve#realJSOP4-May-19 2:39 
GeneralRe: How to detect advertisement from a Video File Pin
OriginalGriff4-May-19 2:44
mveOriginalGriff4-May-19 2:44 
AnswerRe: How to detect advertisement from a Video File Pin
Gerry Schmitz4-May-19 3:06
mveGerry Schmitz4-May-19 3:06 
QuestionHow to get the Average with No LINQ code ! Pin
Abdalla Ben Omran3-May-19 4:19
Abdalla Ben Omran3-May-19 4: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.