this is a program that counts the number of letters, words, and sentences from input text. in the final section, I am attempting to use a formula and I keep getting a floating point exception. Please help.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <math.h>
int main(void)
{
char text[100];
int number;
int words = 0, i;
int sentences = 0, j;
float l = number / words * 100;
float s = sentences / words * 100;
int index = 0.0588 * l - 0.296 * s - 15.8;
int grade = round(index);
// Text Input = Text //
printf("Text: ");
fgets(text, sizeof(text), stdin);
printf("%s", text);
// Letters = number //
number = strlen(text);
printf("%d letters\n", number);
// Words = words //
for (i = 0; text[i] != '\0'; i++)
{
if (text[i] == ' ' && text[i+1] != ' ')
words++;
}
printf("%d words\n", words + 1);
// Sentences = sentences
for (j = 0; j < strlen(text); j++)
{if (text[j] == '.' || text[j] == '!' || text[j] == '?')
sentences++;
}
printf("%d sentences\n", sentences);
// grade level based on formula //
if (index >= 1 && index <= 16)
{
printf("Grade %d\n", grade);
}
else
{
if (index < 1)
{
printf("Before Grade 1\n");
}
if (index > 16)
{
printf("Grade 16+\n");
}
}
}
I keep getting a floating point exception with the final section starting at grade level based on formula . . . the float l, float s, int index, int grade are involved with the final section . . . no idea what to do