Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading