Question

I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

I'm having trouble getting my program to output this statement

Enter a sentence: Test!

There are 5 total characters.
There are 1 vowel.
There are 1 UPPERCASE letters.
There are 3 lowercase letters.
There are 1 other characters.

Here's my code:

#include<string.h>

#include<stdio.h>

#include<stdbool.h>


int main() {

char str[100];

int i;

int vowels=0;

int UC;

int LC;

int Others;

int c;

printf("Enter a sentence: \n");

gets(s);

LC=countLC(&s);

UC=countUC(&s);

Others=countOthers(&s);

printf("There are %d total characters.\n", ;

for(i=0; i<strlen(str); i++){

if(isVowel(str[i]))

vowels++;

}

printf("There are %d vowels.\n", vowels);

printf("There are %d UPPERCASE letters.\n", UC);

printf("There are %d lowercase letters.\n", LC);

printf("There are %d other characters.\n", Others);


return(0);

}

bool isVowel(char ch){

if (ch =='a' || ch=='e'|| ch=='i' || ch== 'o' || ch=='u' ||

ch =='A' || ch=='E'|| ch=='I' || ch== 'O' || ch=='U')

return true;

else

return false;

}

int countUC(char *str){

int count=0, i=0;

for(i=0; i<strlen(str); i++){

if(str[i]>=65 && str[i]<=90)

count++;

}

return count;

}

int countLC(char *str){

int count=0, i=0;

for(i=0; i<strlen(str); i++){

if(str[i]>=97 && str[i]<=122)

count++;

}

return count++;

}

int countOthers(char *str){

return countOthers;

}

int countVowel(char* str) {

char*s= str;

int vowel=0;

while(*s!='\0') {

if(isVowel(*s)) {

vowel++;

}

s++;

}

return vowel;

}



0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<string.h>
#include<stdio.h>
#include<stdbool.h>

bool isVowel(char);
int countUC(char *);
int countLC(char *);
int countOthers(char *);
int countVowels(char *);

int main() {
    char str[100];
    int i;
    int vowels = 0;
    int UC;
    int LC;
    int Others;
    int c;
    printf("Enter a sentence: \n");
    gets(str);
    LC = countLC(str);
    UC = countUC(str);
    Others = countOthers(str);
    printf("There are %d total characters.\n", strlen(str));
    printf("There are %d vowels.\n", countVowels(str));
    printf("There are %d UPPERCASE letters.\n", UC);
    printf("There are %d lowercase letters.\n", LC);
    printf("There are %d other characters.\n", Others);
    return (0);
}

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;
}
Add a comment
Know the answer?
Add Answer to:
I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm having trouble getting my program to output What is your first name? damion what is...

    I'm having trouble getting my program to output What is your first name? damion what is your last name? anderson damion, Your first name is 6 characters Your last name, anderson, is 8 characters Your name in reverse is: noimad nosredna This is my code so far: #include <stdlib.h> #include <stdio.h> void sizeOfName(char** name); void printSizeOfName(int *first, int *last, char** name); void reverseString(int *first, int *last, char** name); int main() {   char** name;   name = (char**)malloc(2*sizeof(char*));   name[0] = (char*)malloc(100*sizeof(char));   name[1]...

  • I'm having trouble getting a certain output with my program Here's my output: Please input a...

    I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...

  • I was asked to write a program that when divisible by 2- reverses the order of...

    I was asked to write a program that when divisible by 2- reverses the order of the letters in a sentence when divisible by 3- changes all lowercase letter into uppercase letters in a sentence when divisible by 5 skips the vowels in a sentence this is what I have so far. my reverseMode works fine. #include <iostream> #include <string> #include<cstring> using namespace std; void reverseMode(char* str); void upperMode(char* str); void goodbyeVowels(char* str); char str[50], rstr[50]; //initializing my character arrray...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...

  • i'm trouble getting my program to print this output and repeat until asked to quit the...

    i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...

  • Write a program that reads a sentence input from the user. The program should count the...

    Write a program that reads a sentence input from the user. The program should count the number of vowels(a,e,i,o,u) in a sentence. Use the following function to read the sentence. Should use switch statement with toupper. int read_line(char str[],int n) {    int ch, i=0;    while((ch =getchar()) != '\n')        if(1<n)            str[i++]==ch;    str[i] != '\0';    return i; } output should look like: Enter a sentence: and thats the way it is! Your sentence...

  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Write a program that replace repeated three characters in a string by the character followed by 3...

    Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT