Have to do this and not sure how to do it. Need help with doing it.
Instructions:
Query the user for the name of a file and then count and
report the number of words that do not begin with the letter d, irrespective of case and the
number of words that do begin with the letter d, irrespective of case.
Currently the code, finds vowels in the text file that is inputted, it needs to be fixed so that it can count and report the number of words that do not begin with the letter d, irrespective of case and the number of words that do begin with the letter d, irrespective of case.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cctype>
int main() {
std:: string fileName;
std::cout << "Enter name of file: ";
std::getline(std::cin, fileName);
std::ifstream inFile(fileName.data());
if (!inFile)
return (std::cout << "Cannot open file\n"), 1;
unsigned dCount {}, wrdCount {};
for (std::string line; std::getline(inFile, line);) {
std::istringstream lss(line);
for (std::string word; lss >> word; ++wrdCount)
dCount += static_cast<char>(std::toupper(static_cast<unsignedchar>(word.front()))) == 'D';
}
std::cout << "There are " << dCount << " words that begin with d\n";
std::cout << "There are " << wrdCount - dCount << " words that do not begin with d\n";
}