This program is suppose to count the number of digits, words ( i.e Abc, fish...) upper case letters, and longest word length inputted.
I am having trouble properly writing the code to identify word count and number of letters inputted. When I run it only the number of digits seen seems to work and I do not know how to make the program count the longest word inputted.Am I on the right track? Any help is greatly appreciated!
int main(){
char s = '0';
char sentinel = '.';
int countWords = 0;
int countDigits = 0;
int countLetters = 0;
int countUppers = 0;
cout << "Enter your string: " << endl;
while (cin >> s){
if (isdigit(s)){
countDigits++;
}
else if (isupper(s)){
countUppers++;
}
else if (isspace(s)){
countWords++;
}
cout << "# of Digits: " << countDigits << endl;
cout << "# of Uppers: " << countUppers << endl;
cout << "# of Words: " << countWords << endl;
cout << "Longest word length" << countLetters << endl;
}
system("PAUSE");
}
/*getline(cin, s);
const int size = s.length();
cout << "The total number of characters entered is: " << size << endl;*/
First post code in code tags (the "<>" on the toolbar)
Second, your code is going to print count each time it reads a character
Third, avoid using platform specific extensions such as system
Modified you code to calculate and print the statistics properly