getting vowels and consontants

closed account (ETA9216C)
I am working on a code that is suppose to get vowels and consonants from a string. So far i got up to trying to get the vowels from a string. this is what i have so far:
Am i doing this right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>      // includes go into header

using namespace std;


 int getword(string word);
 int getvowels(string word);

int main();
{
		string word;

		getword(word);
		getvowels(word);

		return 0;
}

int getword(string word);
{

	cout<<"Type a word(s): ";
	getline(cin,word);
	cout<<endl;

	return word;
}

 int getvowels(string word)
 {
	 int words[100];
	 int vowels[6]={"a","e","i","o","u","y"};
	 int numofvowels=0;


	 for(int i=0,i<=100,i++)
	 {
		for(int j=0, j<=6,i++)
		{
		   if (words[i]== vowels[j])
			 numofvowels++;


		} //vowel for loop
	 } //word for loop
		  cout<< "there are "<<numofvowels<<" vowels.";

	 return 0;
 }
@lookerup

There are a few small errors in your program. I corrected them, and placed it below your program.
If you have any questions about the corrections/additions, please ask.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>      // includes go into header

using namespace std;

 int getword(string word);
 int getvowels(string word);

int main();
{
		string word;

		getword(word);
		getvowels(word);

		return 0;
}

int getword(string word);
{

	cout<<"Type a word(s): ";
	getline(cin,word);
	cout<<endl;

	return word;
}

 int getvowels(string word)
 {
	 int words[100]; // Not needed. 
	 int vowels[6]={"a","e","i","o","u","y"}; // These are chars, not ints
	 int numofvowels=0;


	 for(int i=0,i<=100,i++)
	 {
		for(int j=0, j<=6,i++) // The vowel array is 0 to 5, only. And the loops should be separated with ;, not ,
		                                 // It's also j++, not i++
                {
		   if (words[i]== vowels[j]) // Not checking the word line.
			 numofvowels++;


		} //vowel for loop
	 } //word for loop
		  cout<< "there are "<<numofvowels<<" vowels.";

	 return 0;
 }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// vowels.cpp : main project file.

#include <iostream>
#include <string>      // includes go into header

using namespace std;

 void getword(string word);
 void getvowels(string word);

int main()
{
		string word;

		getword(word);
		
		return 0;
}

void getword(string word)
{

	cout<<"Type a word(s): ";
	getline(cin,word);
	cout<<endl;
	getvowels(word);

//	return word;
}

void getvowels(string word)
 {
	 int word_len = word.length();
	 char vowels[6]={'a','e','i','o','u','y'};
	 int numofvowels=0;


	 for(int i=0;i<word_len;i++)
	 {
		for(int j=0;j<6;j++)
		{
		   if (word[i]== vowels[j])
			 numofvowels++;
		} //vowel for loop
	 } //word for loop
		  cout<< "there are "<<numofvowels<<" vowels.";
 }


closed account (ETA9216C)
Thank you, I'm still trying to get a hang of c++.
Topic archived. No new replies allowed.