#include #include #include #include #include #include int main() { std::vector words; std::string someword; std::string const end_input("end"); int totallength(0); int average(0); int vowel(0); int con(0); int ratiocon(0); int ratiovowel(0); bool reject = false; try { do { std::cout << "Input a word: ('end') to exit\n"; std::cin >> someword; for (size_t index(0); index < someword.length() && not reject; index++) { if (isalpha(someword[index])) continue; else reject = true; } if (reject) throw std::exception(); if ( someword != end_input ) { words.push_back(someword); totallength += someword.length(); average = totallength / words.size(); for (size_t index(0); index != someword.length(); ++index) { char c(0); c = someword[index]; switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': ++vowel; break; default: ++con; } } } else break; } while (true); std::cout << "Average length of these words is " << average << '\n'; std::cout << "There are " << vowel << " vowels and " << con << " consonants\n"; int m(vowel); int n(con); int r(0); int gcd(0); do { r = m % n; if (r==0) { gcd = n; break; } m = n; n = r; } while (true); ratiovowel = vowel/gcd; ratiocon = con/gcd; std::cout << "The ratio of vowels to consonants is " << ratiovowel << ":" << ratiocon << '\n'; } catch (...) { std::cerr << "***An Exception was thrown***\n"; } }