Question: Can someone help me fix my program. My professor claimed that when he had entered a text file with 12 words starting with the letter

Can someone help me fix my program. My professor claimed that when he had entered a text file with 12 words starting with the letter 'D' or 'd' it brought back up 10. Here is the problem:

Query the user for the name of a file. Open and process that file, reporting the number of words that begin with the letter d, irrespective of case. The input file for testing this assignment is posted on Blackboard.

Program is in C++

Input file:

Dozens of years ago in a drafty castle Duke David of Dundeedle did dwell. David's dimpled daughter Dora was a delight. oscar

Program:

#include  #include  #include  #include  #include  using namespace std; int main(void) { int count; char curr, prev; string inputFileName; string s; ifstream fileIn; cout<<"Enter name of file of characters :"; cin>>inputFileName; fileIn.open(inputFileName.data()); assert(fileIn.is_open() ); curr=' '; count=0; while(!(fileIn.eof())){ prev=curr; curr=fileIn.get(); if(prev==' '){ switch (curr){ case 'd': case 'D': count++; } } } cout<<"The number of words starting with the letter D are "<return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!