0

I am currently working through the CS50 course and ran into an issue. I am using the CS50 IDE and for some reason I can't seem to do basic math operations... I'm not sure why this is but the code at the bottom just will not calculate the index. And the avgsentences and avgword just keeps coming out as the original sentences and word amounts.

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main (void)
{

 string text;

 text = get_string("Text: ");

 //Count the number of letters, words, and sentences in the text
 int letters;
 int word = 1;
 int sentences = 0;

 for (int i = 0; i < strlen(text); i++)
 {
     if(isalpha(text[i]))
     {
         letters = letters + 1;
     }
     else if(text[i]==' ' || text[i]=='\0')
     {
         word = word + 1;
     }
     else if(text[i] == '.' || text[i] == '!' || text[i] == '?')
     {
         sentences = sentences + 1;
     }


 }

 //Average per 100 words
 float avgletters = (100 / word) * letters;
 float avgsentences = (100 / word) * sentences;

 double index = 0.0588 * avgletters * 0.296 - avgsentences - 15.8;

 printf("Letter(s): %f\n", avgletters);
 printf("Word(s): %i\n", word);
 printf("Sentences: %f\n", avgsentences);
 printf("Index: %f\n", index);

}```
LBplshelp
  • 1
  • 2
  • Does this answer your question? [What is the behavior of integer division?](https://stackoverflow.com/questions/3602827/what-is-the-behavior-of-integer-division) – UnholySheep Jan 25 '20 at 15:37
  • It is not the IDE, it's your not-yet-complete understanding of the C language, which leads to your problem. See the linked other question. And you might like to ask CS50 questions at the [specialized StackExchange site](https://cs50.stackexchange.com/). – the busybee Jan 25 '20 at 18:18

0 Answers0