#include #include #include #include #include //for the function islower #include //for class back_inserter #include //for the functions copy_if, count using namespace std; //The house with functions and autos. int main() { vector alphabet; //will hold the input characters cout << "Please input a sentence (please input lowercase) "; string sentence; getline(cin, sentence); //cin is limiting, replaced with getline. if (!cin) { cerr << "Sorry, couldn't receive input.\n"; return EXIT_FAILURE; } //Copy the lowercase letters from sentence to alphabet. copy_if(begin(sentence), end(sentence), back_inserter(alphabet), [](char c) {return islower(c);}); const vector::size_type n {alphabet.size()}; char freqletter {'\0'}; //the most popular letter int mostused {0}; //how many times the most popular letter appeared for (auto letter: alphabet) { //for each letter in alphabet, const vector::difference_type timesused {count(begin(alphabet), end(alphabet), letter)}; if (timesused > mostused) { mostused = timesused; freqletter = letter; } } cout << "Your sentence has the letter, " << freqletter << ", used" << " " << mostused << " time"; if (mostused != 1) { cout << "s"; } cout << ".\n"; return EXIT_SUCCESS; }