Complete the program named WordAvg
below so
that it reads in a string of one or more lines, determines the number of
words in the string, counts the number of letters in each word, and prints
out the average number of characters per word in the string. The average
should be printed to two decimal places.
Input: a string containing one or more lines of words
Output: the average number of characters per word in the input string to two decimal places
For example, the string "Joe jumps to grab the ball" has six words (and five spaces). There are a total of 21 characters in the six words. So the average number of characters per word in this string is 3.50.
As another example, the string containing the following lines
Peter Piper picked a peck of pickled peppers A peck of pickled peppers Peter Piper picked If Peter picked a peck of pickled peppers Wheres the peck of pickled peppers Peter Piper picked
contains a total of 33 words and 153 characters. So the average number of characters per word for this string is 4.64.