+ 1
Average word length Problem.
My last test case is failing. Don't know why. Can anyone tell me. Here is my code đ https://code.sololearn.com/ctUdsqs3zyvF/?ref=app
10 Respostas
+ 4
The last test case fails because you effectively don't consider the last character of the sentence by decrementing 'n' in line 11 (the loop will stop at the second-last character, not the last). If you delete that line, everything should be fine.
+ 2
Rishi You have a point, but the test cases are not terminated by a newline character, hence the difference to actual input from the console.
Regarding your code, 50 characters seem awfully short for an english essay. You might want to allow for some more text.
+ 2
Itzel Medina those are not numbers. The characters have ASCII values right? '0'=48,'1'=49,... So he's checking if the characters are numbers using those conditions. Same with the following numbers. You'll understand it when you see the respective ASCII values of the numbers he used
+ 1
oohh now I get it, thanks! đ
0
Shadow doesn't his code already correct? Because when you get a string with fgets from the stdin(for example "me"), the length will be one greater than the original length(in this case it would be 3). Then his code does consider the last character of the sentence.
0
Shadow just tested it in sololearn and I was wrong. But for some reason, Cxxdroid followed my logic. Also, doesn't it make sense because an extra newline will be recorded by fgets() function?
0
Shadow and if you can, see my code(fails 5th test case)
https://code.sololearn.com/cZPNJwCHHz9o/?ref=app
0
Shadow oh okay I'll try that
0
Shadow thank you so much! It worked. It's really amazing to know that it's that 50 character length that wasn't enough. I didn't know that and was trying for days. Thank you again. Have a nice day
0
Hi! Can you explain the logic behind your code? I'm very new on all this about programming and I already did the exercise, but I want understand the logic behind your code, I can't understand it đ
, why you put those numbers in the conditionals? (I'm not sure if said it right, my english isn't very good btw đ
),