I am making a program that is supposed to check how many vowels are in a string of characters, it works fine except when a space is included, in these cases it only counts how many vowels are before the space then it breaks the loop and closes the program
#include <iostream>
#include <string>
int main()
{
const std::string vowels = "aeiouAEIOU" ;
std::cout << "Hello and welcome to my vowel counting program!\n" ;
char Cont = 'n';
do
{
std::cout << "\nPlease enter a string of characters: ";
// http://www.mochima.com/tutorials/strings.html
std::string Counted ;
// http://www.cplusplus.com/reference/string/string/getline/
std::getline( std::cin, Counted ) ; // unformatted input: does not skip leading white space
int VowelsTotal = 0;
for ( char c : Counted ) // http://www.stroustrup.com/C++11FAQ.html#for
{
// http://www.cplusplus.com/reference/string/string/find/if( vowels.find(c) != std::string::npos ) ++VowelsTotal ;
}
std::cout << "\nThere are " << VowelsTotal << " vowel(s) in that string!\n\n" ;
std::cout << "Would you like to go again? (y/n): ";
std::cin >> Cont; // leaves trailing white space (new line) in the input buffer
// http://www.cplusplus.com/reference/istream/istream/ignore/
std::cin.ignore( 100, '\n' ) ; // throw away the trailing white space (new line)
} while ( Cont == 'y' || Cont == 'Y' );
}