#include #include using namespace std; bool Vowel (string, int); bool HasVowel (string, int); int main () { string word; string syl; int start; int end; int last; int spot; int trial; bool done = false; cout << "Enter: "; do { cin >> word; spot = word.find('.'); if (spot > 0) { word = word.substr(0,spot); done = true; } start = end = 0; last = word.size() - 1; while (end <= last) { if (Vowel(word, start)) { end++; while (end <= last && Vowel(word, end)) end++; if (end > last) syl = word.substr(start, end-start); // v* else { syl = word.substr(start, end-start+1); // v*c trial = end + 1; while (trial <= last && !Vowel(word, trial)) trial++; if (trial > last) { syl = word.substr(start, trial-start); // v*c*# end = trial; } } cout << syl; } else { end++; while (end <= last && !Vowel(word, end)) end++; while (end <= last && Vowel(word, end)) end++; trial = end; if (end == last) trial = end + 1; // c*v*cc# or c*v*cv# else if (end < last && !Vowel(word, end+1)) trial = end + 1; // c*v*c syl = word.substr(start, trial-start); // otherwise c*v*c end = trial - 1; cout << syl; } end = start = end + 1; if (end <= last && HasVowel(word, end)) cout << '-'; else if (end <= last) { cout << word.substr(end, 100); // attach rest end = last + 1; } } cout << endl; }while (!done); return 0; } bool Vowel (string hold, int pos) { char let; if (hold[pos] == 'y' && pos > 0) return true; let = hold[pos]; if (let == 'a' || let == 'e' || let == 'i' || let == 'o' || let == 'u') return true; else return false; } bool HasVowel (string hold, int pos) { int limit = hold.size(); for (; pos < limit; pos++) if (Vowel(hold, pos)) return true; return false; }