im trying to write this code in a particular way but my programme seems to keep getting the letter counts wrong.
running debug 50 it seems that the bool i have created (letter) does not change from true to false during iterations.
is there something wrong in my synatax that is preventing this from happening? any other help with my code is also appreciated.
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
// DECLARE LETTER, WORD & SENTENCE COUNT
int letters = 0;
int words = 1;
int sentences = 0;
// DECLARE THE USERINPUT AND ITS COUNTER
string userinput;
int checkinput;
//OBTAIN A VALID INPUT
do
{
userinput = get_string("input text: ");
checkinput = strlen(userinput);
}
while (checkinput <= 0);
// CREATE BOOLEAN EXPRESSION FOR IDENTIFYING LOWERCASES, UPPERCASES, WORDS AND SENTENCES
int lettersIterate = 0;
bool letter = (isalpha(userinput[lettersIterate]));
// ITERATE THROUGH THE TEXT TO FIND LETTER COUNT
for (; lettersIterate <= checkinput; lettersIterate++)
{
if (letter == true)
{
letters++;
}
if (userinput[lettersIterate] == ' ')
{
words ++;
}
if (userinput[lettersIterate] == '.' || userinput[lettersIterate] == '?' || userinput[lettersIterate] == '!')
{
sentences++;
}
}
printf("letters %i\n", letters);
printf("words %i\n", words);
printf("sentences %i\n", sentences);
}