Average World Length | Sololearn: Learn to code for FREE!

+2

Average World Length

My code is passing almost all test instead of 1 test case. https://code.sololearn.com/cpKcYFetit6s/?ref=app Please fix this, If I'm entering "Can you not do that?" It's printing 4 ,But it should be print 3.

c++

5/20/2022 11:25:31 AM

Manav Roy

7 Answers

New Answer

+2

By testing your code! You know int/int result int only.. So argument to ceil is int value, and it returns same value. No effect. Need a double value to get double type result in division.

+2

Jayakrishna🇮🇳 Thank you very very very very much🙏❤️

+1

Manav Roy length -= SpecialChars; After the correction, convert length or NoOfWords as double type or declare as double type. Use like this : cout<<ceil((double)length/NoOfWords);

+1

You're welcome..

0

I guess, you've forgot to substract number of special symbols from length of sentence in final answer: ceil((length-SpecialChars)/NoOfWords) But anyway, easier way to do this task is just divide number of letters (those, for which isalpha is 1) by number of spaces, increased by one (which indicates number of words): LettersCount / (SpacesCount + 1)

0

Alexus100 length-=SpecialChars; If i do add this condition, It's successfully passing the first test case ,But not remaining 4.

0

Jayakrishna🇮🇳 It works fine,How did you figure it out?