Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

Name soe entities and attributes in a furniture store environment.

Answered: 1 week ago