Question: Can someone help me fix up my code? I am trying to make a code that when I type in a sentence, the program counts

Can someone help me fix up my code? I am trying to make a code that when I type in a sentence, the program counts and displays how many vowels, constants, digits, and white spaces there are. When I run this code and type a sentence down, it shows that the values of the things I am looking for is zero.

This is the code I have so far.

#include

using namespace std;

int main() {

char input;

cin >> input;

char str[] = {input};

int vowels, consonants, digits, spaces;

vowels = consonants = digits = spaces = 0;

for(int i = 0; str[input]!='\0'; ++i) {

if(str[input]=='a' || str[input]=='e' || str[input]=='i' ||

str[input]=='o' || str[input]=='u' || str[input]=='A' ||

str[input]=='E' || str[input]=='I' || str[input]=='O' ||

str[input]=='U') {

++vowels;

} else if((str[input]>='a'&& str[input]<='z') || (str[input]>='A'&& str[input]<='Z')) {

++consonants;

} else if(str[input]>='0' && str[input]<='9') {

++digits;

} else if (str[input]==' ') {

++spaces;

}

}

cout << "The string is: " << str << endl;

cout << "Vowels: " << vowels << endl;

cout << "Consonants: " << consonants << endl;

cout << "Digits: " << digits << endl;

cout << "White spaces: " << spaces << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!