Maintainability is an important part of coding.
I see where you are going with the name of the function. But if you go 80% there you may as well go the whole way. Name the function for what it does (don't chop the words).
// Would have preferred
Are you really returning an integer from the function? By your use case above you assign the result to a double. But if you return an int you will truncate the value. ie. you will get 2 rather than 2.5 etc.
Here you assign to double. So I suspect you want to actually return a double.
answer = average_of_let_wor();
As pointed out by
@Morwenn. Counts are usually integer. Personally I would also make them integer (but this will cause a slight problem below when you calculate the answer (as integer division returns an int so at that point you must coerce the values back to a double)). Thus this is really a 50/50 coin flip on which is the better technique and leaving them as double is quite acceptable.
double numberOfLetters = 0;
double numberOfWords = 0;
The easy way to check for space is
if (userInput == ' ' || userInput == '\t' || userInput == '\n')
But these are not the only space characters so be careful. If your specs say only to test for these three then using isspace() may give you different results.
You are forgetting to test if the last character was a space. Thus words separated by double space count as two words (or more (if you use more spaces)). Also do you need to take into account punctuation and other characters?
Its a good habit to use braces on all nested code blocks.
There are some corner cases where you may accidentally modify the code and a subsequent statement is not inside the else branch (and it is hard to spot (say inside a macro). So for maintainability please get into the habit of using
Here I totally disagree with
answer = numberOfLetters/numberOfWords;
There is nothing wrong with assigning the result to answer. It will make absolutely no difference to the resulting code that is generated and it helps document the code by explaining what you are doing here.
Another added advantage is that when you are debugging, you can hover over the variable
answer and see that it has been correctly defined.