Advertisement
Guest User

first array task lab5

a guest
Oct 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int age[4];
  6.  
  7. int main()
  8. {
  9. for (int i = 0; i < 5; i++)
  10. {
  11. cout << "please enter your age \n";
  12. cin >> age[i];
  13.  
  14. }
  15. int total = 0;
  16. for (int i = 0; i < 5; i++)
  17. total += age[i];
  18. double avg = total / 5;
  19.  
  20. cout << "the average age of your group is " << avg << endl;
  21.  
  22. int lower = 0;
  23. int higher = 0;
  24.  
  25. for (int i = 0; i < 5; i++)
  26. {
  27. if (age[i] < avg)
  28. lower++;
  29. }
  30. for (int i = 0; i < 5; i++)
  31. {
  32. if (age[i] > avg)
  33. higher++;
  34.  
  35.  
  36. }
  37. cout << "number of ages higher than the average:";
  38.  
  39. cout << higher << endl;
  40.  
  41. cout << "number of ages lower than the average:";
  42.  
  43. cout << lower << endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement