for( k = 0; k < n; k++ )
{
total += total + temps[k];
}
avgTemp = total / n;
temps is my array that contains n elements. avgTemp stores the average of all the values in temps. k is just some integer to make my loop work. k, n, and total are already declared appropriately somewhere above. total keeps track of the total of the elements in the array.
My exercise thing is telling me this is wrong. What am I doing wrong?
double avgTemp = std::accumulate(temps,temps+n,0.0) / n;assumingtempsis a bunch of temperatures stored as floating point values.