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
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
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;
bool answer = true..
const int arraylength = 5;
int array[arraylength]={1,3,5,2,4};
//...mrboolf code
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.