0

average=a[counter]+b[counter]+c[counter]+d[counter]/12;


can someone can help me? modify to modify this code using an for loop? thanks

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by vmanes
0

If all the values are stored in the same array of length arraylength then this will work

int average = 0;
     for(int i = 0; i<arraylength; i++) {
          average += array[i];
     }
     average /= arraylength;
0

bool answer = true..

const int arraylength = 5;
int array[arraylength]={1,3,5,2,4};

//...mrboolf code
0

Do you mean that you have four separate arrays, and you're trying to find the average across them?

If so, enclose your code inside a loop, controlled by variable "counter"

One correction, to get the average

average= ( a[counter]+b[counter]+c[counter]+d[counter] ) / 12;

enclose the addition in parentheses so all the values are added, then the division occurs. As you wrote it, d[counter] was divided by 12, then added to the other three values.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.