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
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
Get step-by-step solutions from verified subject matter experts
