fork download
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. const int heightCount = 8;
  7. int kidHeights[heightCount] = { 1, 3, 6, 5, 6, 4, 2, 3 };
  8.  
  9. // your first for loop
  10. auto maxHeightIter = std::max_element(kidHeights, kidHeights + heightCount);
  11.  
  12. // your second for loop
  13. auto maxHeightCount = std::count(kidHeights, kidHeights + heightCount, *maxHeightIter);
  14.  
  15. std::cout
  16. << "Highest kid is " << *maxHeightIter
  17. << " unit(s) high and number " << maxHeightIter - kidHeights + 1
  18. << " in line.\nThere are " << maxHeightCount
  19. << " kids with this height, in total." << std::endl;
  20. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Highest kid is 6 unit(s) high and number 3 in line.
There are 2 kids with this height, in total.