I have problem to start. I need algorithm for program that prompts the user to input a sequence of characters and outputs the number of vowel, using user-defined value returning function Vowel.

Please help

I have problem to start. I need algorithm for program that prompts the user to input a sequence of characters and outputs the number of vowel, using user-defined value returning function Vowel.

Please help

So you want to count how much times a certain vowel is encountered in the sequence of characters?

e.g. : aabcc
a: 2
b: 1
c: 2

Is this right?

So you want to count how much times a certain vowel is encountered in the sequence of characters?

Is this right?

Yes, I need get number of vowels in the sequence.

Yes, I need get number of vowels in the sequence.

Then you might want to take a look at this code snippet :)

Thank you very much:idea:

This is my final code of program that counts vowels.

#include "stdafx.h"
#include <iostream>
//=================

//======================
	using namespace std;
//======================

//======================
//Function Prototypes
//======================
	bool isVowel ( char );
//======================




// IsVowel Function
//+++++++++++++++++++
	bool isVowel (char letter) {
		switch (letter) {
			case 'a': return true;
			break;
			case 'e': return true;
			break;
			case 'i': return true;
			break;
			case 'o': return true;
			break;
			case 'u': return true;
			break;
			case 'y': return true;
			break;
			default: return false;
		}//switch
	} // isVowel function
int main()
{

// Variable Declaration
//+++++++++++++++++++++

	int vowelcounter;
	char letter;
	char askuser;
	char repeat;
	bool loop;
	bool finished = true;
//+++++++++++++++++++++++

//+++++++++++++++++++++++
//Welcome Screen
//++++++++++++++
	cout << " " << endl;
	cout << "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" << endl;
	cout << "Y                                    Y" << endl;
	cout << "Y   Welcome to the IsVowel program   A" << endl;
	cout << "A                                    A" << endl;
	cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl;
	cout << " " << endl;
// Loop
//+++++

	do {
		loop = true;
		vowelcounter = 0;
//+++++++++++++++++++++++

//+++++++++++++++++++++++
		do {
			cout << " Enter a character " << endl;
			cin >> letter;
			if (isVowel (letter))
				vowelcounter++;
			cout << " Would you like to enter another character? (y/n) " << endl;
			cin >> askuser;
			if ( askuser == 'n' ) {
				loop = false;
			}
		}// 2nd do
		while (loop);
		cout << " Number of vowels: " << vowelcounter << endl;
		cout << " Would you like repeat? (y/n) " << endl;
		cin >> repeat;
		if (repeat == 'n')
			finished = false;
	} while (finished);


	return 0;
}

if it help you use it welcome.

You can write your isVowel function in less lines :P
(It can still be written more efficiently, but I want to demonstrate it using a switch case, because the OP used that statement in his code)

bool isVowel (char letter) {
	switch (letter) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        case 'y': return true;
        break;
        default: return false;
	}
}

>It can still be written more efficiently
I'm curious, how could it get more efficient than that?

>It can still be written more efficiently
I'm curious, how could it get more efficient than that?

If you're talking about CPU efficiency, I can't think of anything that'll run faster then the code already posted, then I have no idea.
If you want less lines of code, you could do something like:

bool isVowel(char letter){
    std::string vowels="aeiouy";
    if (vowels.find(letter) == std::string::npos) return false;
    return true;
}

>It can still be written more efficiently
I'm curious, how could it get more efficient than that?

A lookup table comes to mind (for a "speed" type of efficiency).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.