+ 2

Can some one help me debug my code it in the challenge of average word length?

My problem is when i calculate the average word length of test case using a calculator i get 4.4286 .Which is four in interger but the answer they are saying is 5 but test case 1 and 4 are right but the others its sayi is wrong https://code.sololearn.com/crvLiIp29RTA/?ref=app

30th Aug 2022, 11:33 AM
Daniel Kagombe
Daniel Kagombe - avatar
4 Answers
+ 2
I have solved it by checking if th average word length divided by number of word has a remeinder if not average word length will be whole number if yes average word length is added by on float ans=word_length/(count+1); // prints average word length if((word_length%(count+1))!=0){ cout<<++ans;} else{ cout<<ans;} The code at the end !!
30th Aug 2022, 5:40 PM
Daniel Kagombe
Daniel Kagombe - avatar
+ 2
Reading the task description again will help.
30th Aug 2022, 2:06 PM
JaScript
JaScript - avatar
30th Aug 2022, 5:45 PM
Daniel Kagombe
Daniel Kagombe - avatar
+ 1
But thanks for your advice it really helped
30th Aug 2022, 6:42 PM
Daniel Kagombe
Daniel Kagombe - avatar