Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why am I getting \"The vowel occured 0 times\" for every vowel? #include <stdio.

ID: 3749027 • Letter: W

Question

Why am I getting "The vowel occured 0 times" for every vowel?

#include <stdio.h>
#include <string.h>

int main (void) {
  
   char word[21];
   int counta = 0;
   int counte = 0;
   int counti = 0;
   int counto = 0;
   int countu = 0;
   int i;

   printf("Enter your strings (lowercase only): ");
   scanf("%s",word);
   for(i=0; word[i]>0;i++) {
       if (word[i] == 'a') {
           counta++;
       }
       if (word[i] == 'e') {
           counte++;
       }
       if (word[i] == 'i') {
           counti++;
       }
       if (word[i] == 'o') {
           counto++;
       }
       if (word[i] == 'u') {
           countu++;;
       }
       else if ((strcmp(word, "quit"))) {
           break;
       }
   }

printf("The vowel a occured %d times. ", counta);
printf("The vowel e occured %d times. ", counte);
printf("The vowel i occured %d times. ", counti);
printf("The vowel o occured %d times. ", counto);
printf("The vowel u occured %d times. ", countu);

return 0;
}

Explanation / Answer

Answer)

I have changed the program to give the correct output:

#include <stdio.h>

#include <string.h>

int main (void) {

  

char word[21];

int counta = 0;

int counte = 0;

int counti = 0;

int counto = 0;

int countu = 0;

int i;

printf("Enter your strings (lowercase only): ");

scanf("%s",word);

for(i=0; word[i]>0;i++) {

if (word[i] == 'a') {

counta++;

}

else if (word[i] == 'e') {

counte++;

}

else if (word[i] == 'i') {

counti++;

}

else if (word[i] == 'o') {

counto++;

}

else if (word[i] == 'u') {

countu++;

}

else {

continue;

}

}

printf("The vowel a occured %d times. ", counta);

printf("The vowel e occured %d times. ", counte);

printf("The vowel i occured %d times. ", counti);

printf("The vowel o occured %d times. ", counto);

printf("The vowel u occured %d times. ", countu);

return 0;

}

Input:

Enter your strings (lowercase only): uuooiieeaaa

Output: