#include #include #include #include using namespace std; void lowerise(string & word) { for (int i = 0; i < word.length(); i += 1) { if (isupper(word[i])) word[i] = tolower(word[i]); } } int main() { ifstream f; f.open("peterpan.txt"); if (f.fail()) { cout << "Couldn't open peterpan.txt\n"; exit(1); } int count = 0, total = 0; while (true) { string word; f >> word; if (f.fail()) break; total += 1; lowerise(word); if (word == "the") count += 1; } cout << "\"The\" appeared " << count << " out of " << total << " times\n"; }