0

I need help in executing the program here. This is my program and when I execute it, it asks me for a text. I copy-pasted the first HOW TO TEST YOUR CODE "One fish. Two fish. Red fish. Blue fish." from the Readability tab in cs50x. My program should print the grade level of the inputted text yet it doesn't and just moves the cursor to the next line. It doesn't end there. If I type something else it just stays there and I press enter and once again it just moves the cursor to the next line. Can someone please look into it and tell me what I've doing wrong. Here is the code I used if anyone can run it and see whats wrong:

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

int main(void) { string s = get_string("Text: "); int num_words, num_sentences, num_letters; num_words = num_sentences = num_letters = 0; for (int i = 0, len = strlen(s); i < len; i++) { if (isalpha(s[i])) num_letters++; if ((i == 0 && s[i] != ' ') || (i != len - 1 && s[i] == ' ' && s[i =1] != ' ')) num_words++; if (s[i] == '.' || s[i] == '?' || s[i] == '!') num_sentences++; } float L = (num_letters / (float) num_words) * 100; float S = (num_sentences / (float) num_words) * 100; int index = round(0.0588 * L - 0.296 * S - 15.8); if (index < 1) printf("Before grade 1\n"); else if (index >= 16) printf("Grade 16+\n"); else printf("Grade %i\n", index);

} enter image description here

  • Please cut and paste the actual code into your questions. It's impossible to copy code from an image and nobody wants to transcribe an entire program to test it. – Cliff B Sep 5 at 19:02
0

This means that your program is getting stuck somewhere. Use "Ctrl + C" to stop the program. If you can please post the code so that someone can run the code and see where its stopping. You can use debugger to see the faulty part of your code as well

| improve this answer | |

You must log in to answer this question.

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