So the first half of my code to find the average works:
but the second half to see if each value in the array is >= or < the average does not work...Code:int main() { const int SIZE = 5; //max array size double x[SIZE] = {1,5,6,8,10}; int num_points = 0; //array index double sum = 0; double avg; for(int i=0;i<SIZE;i++) //for loop to find the sum of array { sum = sum + x[num_points]; num_points++; } avg = sum/SIZE; cout<<"the average of the values in the array is:"<<endl; cout<<avg<<endl;
can anyone tell me why?:
THANKSCode://for loop to find if each value is >= or < the array avg. for(int k=0;k<SIZE;k++) { if(x[k]<avg) cout<<setw(5)<<x[k]<<" is less than the average"<<endl; else cout<<setw(5)<<x[k]<<" is greater than or equal to the average"<<endl; } return 0; }![]()



LinkBack URL
About LinkBacks




