+ 1

Average word length in c - solved

Hello. I have a problem. My code works only for three of the five tests but I don't know why. Can you help me please? Here is my code: https://code.sololearn.com/cbAgFyBRNM2e/#c

13th Oct 2021, 6:53 PM
Madalina Peter
Madalina Peter - avatar
5 Respostas
+ 3
I've found the problem. Thank you very much for your help!
13th Oct 2021, 9:19 PM
Madalina Peter
Madalina Peter - avatar
+ 2
Jayakrishna🇮🇳 I think you are right. It seems like if there isn't anything after the last word it is not taking count of it for calculations. If you put a space after the last word the result is correct
13th Oct 2021, 9:13 PM
Madalina Peter
Madalina Peter - avatar
+ 1
Can you please share the link of problem? or describe a bit about problem...
13th Oct 2021, 7:56 PM
Saurabh
Saurabh - avatar
+ 1
Here is the problem: You are in a college level English class, your professor wants you to write an essay, but you need to find out the average length of all the words you use. It is up to you to figure out how long each word is and to average it out. Task: Takes in a string, figure out the average length of all the words and return a number representing the average length. Remove all punctuation. Round up to the nearest whole number. Input Format: A string containing multiple words. Output Format: A number representing the average length of each word, rounded up to the nearest whole number. Sample Input: this phrase has multiple words Sample Output: 6
13th Oct 2021, 9:08 PM
Madalina Peter
Madalina Peter - avatar
0
According to logic you used in , its not taking the last word count into calculations.. its missing to add last word count,and len to total. Ex : For input : "avg word length" Its taking count=2 , sum=7 but actually need count= 3(add 1), sum=13 (7+6) Hope it helps......
13th Oct 2021, 8:42 PM
Jayakrishna 🇮🇳