fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main () {
  6. const int SZ = 5;
  7. string word[SZ];
  8. int min, max;
  9.  
  10. cout << "Please enter " << SZ << " words: ";
  11. for(int i = 0; i < SZ; i++){
  12. cin >> word[i];
  13. }
  14.  
  15. min = max = word[0].length();
  16.  
  17. for(int i = 1; i < SZ; i++){
  18. if (word[i].length() < min){
  19. min = word[i].length();
  20. }
  21. if (word[i].length() > max){
  22. max = word[i].length();
  23. }
  24. }
  25.  
  26. cout << "min: " << min << ", max: " << max << endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5584KB
stdin
Hello to you Joe Smoe
stdout
Please enter 5 words: min: 2, max: 5