Question: So my code for this gives me the right answer, but the system I have to put it through is very touchy and not accepting

So my code for this gives me the right answer, but the system I have to put it through is very touchy and not accepting it. Any ideas on improvement?

It's supposed to read a series of characters and output the number of vowels.

#include #include

using namespace std;

bool isVowel (char);

int main() { string letters; int num, count = 0;

cout << "Enter a sequence of characters: "; getline(cin, letters); num = letters.length(); for(int i=0; i < num; i++) { if(isVowel(letters[i])) count++; } if (count == 0) cout << "There are no vowels. " << endl; else if (count == 1) cout << "There is 1 vowel. " << endl; else cout << "The number of vowels is: " << count << endl; }

bool isVowel(char ch) { switch (ch) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y': case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } }

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!