+ 2

[SOLVED] Sololearn average word length problem

ALARM 🚨 SPOILER 🚨 if you like to solve sololearn's problems you may want to try your own way before to see the code. If you don't fear any spoiler, check that! https://code.sololearn.com/cmu2JcMtLHFX/?ref=app Do you have any idea about why it doesn't work? Edit: I noticed that if you enter a single word, the program prints an error

18th Oct 2020, 4:11 PM
Davide
Davide - avatar
7 Answers
+ 2
1st mistake,average = ceil( sum / (i-1) ); it should be ceil(sum/i) not i-1 2nd mistake,declaring i as an int when you declare i as an int there is no use of ceil in that line: average = ceil( sum / (i-1) ); because sum/i-1 will return an int as sum and i both are int .So ceil finction can't change the value. So i should be double. 3rd mistake ,in this question they told that "Remove all punctuation" ,I didn't see any code for remove any punctuation . Solve these problem.
18th Oct 2020, 4:54 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
You are not changing word value... Do this : word = strtok( NULL, " " );
18th Oct 2020, 4:22 PM
Jayakrishna 🇮🇳
+ 2
Koral Q Thank you so much!🤗🤗🤗🤗🤗 I am sorry for the lazy asses, it was meant to be an affectionate joke. Of course I am lazier than you!
18th Oct 2020, 4:58 PM
Davide
Davide - avatar
+ 1
Jayakrishna🇮🇳 oh yes I forgot the "word=" part. OMG!
18th Oct 2020, 4:24 PM
Davide
Davide - avatar
0
Here the text of the problem only for you lazy asses willing to help me! 🤗 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
18th Oct 2020, 4:13 PM
Davide
Davide - avatar
0
Jayakrishna🇮🇳 I corrected the error but the program is still failing. If you enter a small sentence it prints the total number of letters insted of the average. However if you try it in the sololearn problem the output is a number around 4million so I am not sure that it prints the number of letters. edit: in the problem the output is the same for different sentences and is exactly 4202500
18th Oct 2020, 4:30 PM
Davide
Davide - avatar
0
NotAPythonNinja thank you for the solution, but I wanted to know what's wrong with my code
18th Oct 2020, 5:00 PM
Davide
Davide - avatar