#include #include #include //for class string using namespace std; //Using the lyrics from //https://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly int main() { struct animal { string name; string comment; }; animal animals[] { {"fly", ""}, {"spider", ""}, {"bird", "How absurd to swallow"}, {"cat", "Well, fancy that, she swallowed"}, {"dog", "What a hog to swallow"}, {"goat", "Just opened her throat and swallowed"}, {"cow", "I don't know how she swallowed"}, {"horse", ""} }; int n {size(animals)}; //the number of animals for (int i {0}; i < n; ++i) { cout << "There was an old lady who swallowed a " << animals[i].name; if (i == 0) { //the first animal cout << ","; } else if (i == n - 1) { //the last animal cout << "..."; } else if (i > 2) { //most of the other animals cout << ";"; } cout << "\n"; //Start a new line. if (i == n - 1) { //the last animal break; //suddenly break out of the for loop } //If this animal has a comment, output the comment. if (animals[i].comment != "") { cout << animals[i].comment << " " << animals[i].name << "!\n"; } for (int j {i}; j >= 1; --j) { if (j == 1) { //the spider cout << " That wriggled and jiggled and " << "tickled inside her,\n"; } cout << " She swallowed the " << animals[j].name << " to catch the " << animals[j-1].name; if (j == 1) { cout << ";"; //Last line ends with semicolon. } else { cout << ","; //Other lines end with comma. } cout << "\n"; } cout << "I don't know why she swallowed a " << animals[0].name << " – perhaps she'll die!\n\n"; } cout << "She's dead, of course!\n"; //Arrive here after the break. return EXIT_SUCCESS; }