Question:
How to make a c program (letters) ?
misc_pic
2009-10-28 17:26:16 UTC
uhm hi there i just like to ask for help cause im quite confuse while im making this program.

the problem is i need to make a program where the user will key in 10 letters and then the program will count how many vowel with in the letter he/she key in. After counting how many vowels, the program should show the result if how many vowels, and also show the letters that he/she key in.

hey here's my program: please tell me which part is wrong and what code is lacking

#include
#include

char letters[10];

int main()
{
char letters;
int count;

printf("please enter at least 10 letters:");
scanf("%c",&letters);

if('a'=='a')
count++;
else if('A'=='A')
count++;
else if('e'=='e')
count++;
else if('E'=='E')
count++;
else if('i'=='i')
count++;
else if('I'=='I')
count++;
else if('o'=='o')
count++;
else if('O'=='O')
count++;
else if('u'=='u')
count++;
else if('U'=='U')
count++;
if(count>1)
printf("there are %d vowels", count);
else
printf("there are %d vowel", count);

getch();
return 0;
}
Three answers:
Mark aka jack573
2009-11-01 17:29:02 UTC
include

#include



//char letters[10]; // Remove this!!!!!!!!!



int main()

{

//char letters; // Change this

char letters[11]; // The reason for 11 is scanf will insert a null character at



the end, so you need a space for the null character

int count;



printf("please enter at least 10 letters:");

scanf("%c",&letters);



for (int i = 0; i < 10 && letters[i] != '\0'; i++) // Add this for loop. It



checks for the null character as well.

{

// Change the if statements

//if('a'=='a')

if(letters[i]=='a')

count++;

//else if('A'=='A')

else if(letters[i]=='A')

count++;

//else if('e'=='e')

else if(letters[i]=='e')

count++;

//else if('E'=='E')

else if(letters[i]=='E')

count++;

//else if('i'=='i')

else if(letters[i]=='i')

count++;

//else if('I'=='I')

else if(letters[i]=='I')

count++;

//else if('o'=='o')

else if(letters[i]=='o')

count++;

//else if('O'=='O')

else if(letters[i]=='O')

count++;

//else if('u'=='u')

else if(letters[i]=='u')

count++;

//else if('U'=='U')

else if(letters[i]=='U')

count++;

} // End the for loop.

// Since you are outputing the number of vowels in this if statment, you don;t need it.

//if(count>1)

//printf("there are %d vowels", count);

//else

//printf("there are %d vowel", count);

printf("there are %d vowel", count); // You only need this line.



// Now you want to print the letters that were keyed in.

for (int i = 0; i < 10 && letters[i] != '\0'; i++)

printf("%c\n", letters[i]);

}



getch();

return 0;

}



Good luck with it.
2009-10-29 00:48:35 UTC
May this helps:



Define Letters only one time.Global or local....Char Letters[10];



initialize count = 0;

Then read the values to Letters i.e.., when user enters the characters they should be stored in Letters array.



Use for loop to start the if loop.Then instead of declaring tens of if's use || command.



for(int k=0; k< 10; k++)

{

if( Letters[0]=='a' || Letters[0] == 'e' || Letters[0] == 'i'|| Letters[0] == 'o'|| Letters[0] == 'u'|| Letters[0] == 'A'|| Letters[0] == 'E' || Letters[0] == 'I' || Letters[0] == 'O' || Letters[0] == 'U' )

count ++;

else

count =0;



Now if (count > 1)

........................



|| -- this symbol is referred as Logical OR see if r compiler uses it other wise you can specify the way you did tens of if's........



Hope this helps.
oops
2009-10-29 02:01:44 UTC
I would do it like this:



http://codepad.org/CGeQFGUq



Don't forget to include


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...