You are using a version without Ads of this website. Please, consider donating:

### can someome please guide me thanks

ok here is the program i need to write...Write a program that takes in 50 values and prints out the highest, the lowest, the average and
then all 50 input values, one per line. ok i will post what i have so far but i'm stuck. i just need a little nudge as i would like to solve this my self, i started with the top down method and decide to write the loop for putting the values but when i go to try and get it to add all the values and average it thats where i'm having problems. also i used 5 instead of 100 as it would be easier to manage for debugging, and i didn't get around to the sort function yet as i am trying to solve the first part i attached the code your help is greatly apprieciated.

 ``12345678910111213141516171819202122`` ``````#include #include using namespace std; int main() { int arrayValues[5]; int sum = 0; int total = 0; int average = 0; for (int i = 0; i < 5; i++) { cout << "Please enter the values: "; cin >> arrayValues[i]; }//end of arrayValues for loop cout << "The sum is: " << total + sum << endl; }//end of main ``````
chaosGlaaze,

`int average = 0;`

int is not a good choice for this variable ( because of integer division)- make it float or double.

You need to accumulate the total inside the for loop. Calc the average after the for loop.

Are total & sum the same thing?

Edit:
You also need code to do the lowest & highest in the for loop.
Last edited on
okay first of all u need to add total with your array's value inside that loop

 ``12345678`` `````` for (int i = 0; i < 5; i++) { cout << "Please enter the values: "; cin >> arrayValues[i]; total += arrayValues[i]; //this will add your array's value to total; }//end of arrayValues for loop ``````

i dont think u need
 `` `` ``cout << "The sum is: " << total+sum<

 `` `` ``cout<< "The sum is: " <

and for average, u should use double/float , (except u want to get the average in lower precision)

so u get the total, and u know the number of values in the array
 `` `` ``average = total / 5;``

for highest and lowest, i think this http://www.cplusplus.com/forum/beginner/77237/ will help u
Last edited on
Topic archived. No new replies allowed.