Created
January 13, 2022 01:13
-
-
Save GermanHoyos/bb92e1ddd4fba7c19ff0eb003d0f73ec to your computer and use it in GitHub Desktop.
Program to find all vowels in a string C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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