Why is my multiplication always returning as 0?

I am new to programming and I am taking CS50 to learn how to program. I am working on the readability code and have hit a block. I can’t get my program to return anything but 0 for the Coleman-Liau index. I have been using debug50 (see attached photo) to try to figure out the problem, but have had no luck. All my other variables are turning out right, but my variable always is returned as 0. I have tried adding parentheses and changing the variable to integers, but nothing has changed. Do you know how I would be able to fix this?

enter image description here

>Solution :

There is a bug in the code. This calculation to obtain "sentences per 100 words"

float s = words / sentences * 100;

should be

float s = sentences / words * 100;

and now you should get A to be 12.638710.


As mentioned by @paddy the testing is also incorrect, excluding A == 1 and it should be

if (A < 1) { ... } else if (A < 16)

Leave a Reply