Advertisement
prprice16

Untitled

Nov 8th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. const int asize = 5;
  2. int nums[asize] = { 0 };
  3. //create accumulator for sum
  4. int sum = 0;
  5. double avg;
  6. //prompt the user to store values into the array
  7. for (int index = 0; index < asize; index++)
  8. {
  9. //sum = sum + nums[index];
  10. //cout << "sum is " << sum << endl;
  11. //prompt for a number
  12. cout << "Enter a number: ";
  13. //store in position [index] of array
  14. cin >> nums[index];
  15. //add this to your accumulator
  16. sum = sum + nums[index]; //or sum += nums[index];
  17. }
  18. //print the total
  19. cout << "sum is " << sum << endl;
  20. //calculate the average
  21. avg = (double)sum / asize;
  22. //print the average
  23. cout << "avg is " << avg << endl;
  24. //print the values greater than avg
  25. cout << "The values above average are" << endl;
  26. for (int index = 0; index < asize; index++)
  27. {
  28. //do I print this number?
  29. if (nums[index] > avg)
  30. {
  31. cout << nums[index] << endl;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement