Hi, ive just recently started using borland c++ v5.02 and am having some difficulty.
I have to write a program that does the following;
1, it should prompt for and allow the user to enter a text string such as one or more sentences
and perform the following actions -
2, it should inform the user of the number of words in the text string
3, it should count and inform the number of upper and lower case characters in the text.
it should count and inform the number of occurences of a given letter, selected by the user,
wether it is present in upper or lowercase within the text; if the letter is not present,
it should state 'not present in text'.
the program may work in either of the following ways;
once the text is entered it may perform each of the tasks in turn, then exits.
the 'search and count for occurance letters' should allow the user to repeat for different letters.
once the text is entered the user is given a menu of choices for the three items above,
and allowed to choose repeatedly without re-running the program. the menu must also include an option to quit
this is what i have so far, but the word count doesn't work correctly and i cant for the life of me figure out how
to do the third task. someone please help me
Code:#include <iostream.h> #include <cstring.h> #include <conio.h> void main() { string s; int uppercase = 0; int lowercase = 0; int chcount=0; //counts non-space characters int wdcount=1; //counts spaces between words char ch = 'a'; cout<<"Enter A Sentence Or Sentences "; getline(cin,s); for (int i =0; i<s.length(); i++) if (isupper(s[i])) uppercase++; else if (islower(s[i])) lowercase++; cout<<uppercase<<" = Number Of Characters That Are Upper Case "<<endl; cout<<lowercase<<" = Number Of Characters That Are Lower Case "<<endl; while( ch != '\r' ) //loop until Enter typed { ch = getche(); if( ch==' ' ) wdcount++; else chcount++; } cout << "\nWords=" << wdcount << endl << "Letters=" << (chcount-1) << endl; }