0

I have just finished doing the Readability problem in pset 2, everything computes correctly except for the final grade. It is always around the -15 or -16 mark.

Below I have added only the code I presume necessary. If you need more let me know and I will edit it.

Any help would be greatly appreciated.

//function declarations

void count_letters(string texts);
void count_words(string texts);
void count_sentences(string texts);
void calc_grade(int l, int w, int s);

//global variables

int letters = 0;
int words = 0;
int sentences = 0;
int grade_int = 0;

//function

void calc_grade(int l, int w, int s)
{

    int L = (l + w) / 2;
    int S = (s + w) / 2;
    float index = 0.0588 * L - 0.296 * S - 15.8;
    grade_int = round(index);
    printf("grade test: %f\n", index);
    return;
}
2
  1. The formulae for L and S are wrong. Those should be the average number of letters and sentences, respectively, on 100 words.
  2. L and S would have to be floating point as well. Also, make sure that the division is a floating point division, by turning at least one operand floating point, by means like multiplying with a floating point number, or an explicit typecast, writing (float) in front of an expression.
3
  • Ok. For 1, I've changed my formulae to float L = (l / w) * 100; float S = (s /w) * 100; . It gives me a closer result but still not right. Any advice for the formula? – Niall Feb 2 '20 at 3:30
  • Ah! I switched the initial int variables to floats and it's all working now. Thanks for the help :) – Niall Feb 2 '20 at 3:36
  • Exactly the same here, your advice about making sure the division is a floating point division solved the same problem here. – Juan Carlos Marcos Prieto Feb 12 '20 at 17:31
0

If it is giving a less than 100% grade, the checker has found something it doesn't like. Quite often, at this stage in the course, its because the program is generating output that is not an exact match to what is required. Usually, it's a misspelled or capitalized word, and extra or missing comment, whitespace, linefeed, or something trivial but required in the output.

Have you carefully checked the output of your program and verified that it exactly matches the required output of the program spec????

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .