Skip to content

Instantly share code, notes, and snippets.

@GermanHoyos
Created January 13, 2022 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GermanHoyos/bb92e1ddd4fba7c19ff0eb003d0f73ec to your computer and use it in GitHub Desktop.
Save GermanHoyos/bb92e1ddd4fba7c19ff0eb003d0f73ec to your computer and use it in GitHub Desktop.
Program to find all vowels in a string C++
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char range);
int main() {
string usrInpt;
int vwlCnt = 0;
bool x;
getline(cin, usrInpt);
//iterate over all the elements in range
//for (delcaration : range){statement};
for (char range: usrInpt) {
x = isVowel(range);
if (x == true) {
vwlCnt++;
}
}
cout << vwlCnt << " vowels in this sentence." << endl;
return 0;
}
bool isVowel(char range) {
if (range == 'a' || range == 'A' ||
range == 'e' || range == 'E' ||
range == 'i' || range == 'I' ||
range == 'o' || range == 'O' ||
range == 'u' || range == 'U') {
return true;
} else {
return false;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment