Question
I'm having trouble getting a certain output in my program The output i'm getting: Enter a sentence: Is THIS another Test??? There are 2 total
I'm having trouble getting a certain output in my program
The output i'm getting:
Enter a sentence: Is THIS another Test???
There are 2 total characters.
There are 1 vowels.
There are 1 UPPERCASE letters.
There are 1 lowercase letters.
There are 0 other characters.
My desired output:
Enter a sentence: Is THIS another Test???
There are 23 total characters.
There are 6 vowels.
There are 6 UPPERCASE letters.
There are 11 lowercase letters.
There are 6 other characters.
Here's my code:
#include
#include
#include
bool isVowel(char);
int countUC(char *);
int countLC(char *);
int countOthers(char *);
int countVowels(char *);
bool isVowel(char ch) {
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
}
int countUC(char *str) {
int count = 0, i = 0;
char ch;
while((ch = str[i++])) {
if(ch >= 'A' && ch <= 'Z') {
++count;
}
}
return count;
}
int countLC(char *str) {
int count = 0, i = 0;
char ch;
while((ch = str[i++])) {
if(ch >= 'a' && ch <= 'z') {
++count;
}
}
return count;
}
int countOthers(char *str) {
int count = 0, i = 0;
char ch;
while((ch = str[i++])) {
if(!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))) {
++count;
}
}
return count;
}
int countVowels(char *str) {
char *s = str;
int vowel = 0;
while (*s != '\0') {
if (isVowel(*s)) {
vowel++;
}
s++;
}
return vowel;
}
int main() {
char str[100];
int i;
int vowels = 0;
int UC;
int LC;
int Others;
int c;
int len;
printf("Enter a sentence: ");
scanf("%s", str);
LC = countLC(str);
UC = countUC(str);
Others = countOthers(str);
len=(int)strlen(str);
printf("There are %d total characters. ",len);
printf("There are %d vowels. ", countVowels(str));
printf("There are %d UPPERCASE letters. ", UC);
printf("There are %d lowercase letters. ", LC);
printf("There are %d other characters. ", Others);
return (0);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started