Indentation
Much about indentation is a style issue. Best to follow your group's style guide. That said I would align comment with code.
//check letter count
if (check == 'l')
to
// check letter count
if (check == 'l')
Spell check
Spelling errors are a distraction and a confusion.
double
vs. float
In C, double
is the default type for floating point constants like 0.0588
. Code is going through lots of gyrations converting form int
to float
to double
and back to float
. I suggest using double
unless required to use float
or code has lots of FP.
// float gradeLevel = (0.0588 * (100 * (float) length(input, 'l') / (float) length(input, 'w')) - 0.296 * (100 * (float) length(input, 's') / (float) length(input, 'w'))) - 15.8;
double gradeLevel = 0.0588 * (100.0 * length(input, 'l') / length(input, 'w'))
- 0.296 * (100.0 * length(input, 's') / length(input, 'w')) - 15.8;
If staying with float
, use float
constants: 0.0588
--> 0.0588f
Rounding (advanced)
round()
returns a double
. C provides a nice way to round to a floating point to an integer type in one step
long gradeLevel = lround(0.0588 * (100.0 * length(input, 'l') / length(input, 'w'))
- 0.296 * (100.0 * length(input, 's') / length(input, 'w')) - 15.8);
...
printf("Grade %ld\n", gradeLevel);