7 Answers
New AnswerBy 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.
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);
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)
Alexus100 length-=SpecialChars; If i do add this condition, It's successfully passing the first test case ,But not remaining 4.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message