Find the word with most vowel, and the word with most consonant

Write a program that ask for a long string and determine the word with the most number of vowel and most number of consonants

example: the quick brown fox jumps over the lazy dog

vowels:quick
consonants : brown


I need some help , I don't know how to separate each words with each having vowel and consonant number , what should I use ? thanks in advance
http://stackoverflow.com/a/237280/1959975

After you have your vector of strings, you can examine each string individually and count the vowels and consonants. Hint: there are fewer vowels than consonants.

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
char v,c;
int Vc=0;
int Cc=0;
string vowels("aeiouAEIOU");
string consonants("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ");

cout << "Enter a sentence: ";
cin.get(c);
while(c != '\n')
{

{
if(vowels.find(c) != string::npos)
Vc++;
cin.get(c);
}

}
while(c != '\n')
{

{
if(consonants.find(v) != string ::npos)
Cc++;
cin.get(v);
}

}
cout << setfill ('.');
cout << " Number of vowels is " << Vc << endl;
cout << " Number of consonants is " << Cc << endl;


return 0;
}
should this need a little change or this completely needs a rewrite ?
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well a proper indentation.

You don't need to know the consonants if you know the vowels.
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
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace std;

int main()
{
	char v,c;
	int Vc=0;
	int Cc=0;
	string vowels("aeiouAEIOU");

	cout << "Enter a sentence: ";
	cin.get(c);
	while(c != '\n')
	{
		
		{
		if(vowels.find(c) != string::npos)
			Vc++;
		cin.get(c);
		}
		
	}
	while(c != '\n')
	{
		
		{
		if(consonants.find(v) != string ::npos)
			Cc++;
		cin.get(v);
		}
		
	}
	 cout << setfill ('.');
	 cout << "  Number of vowels is " << Vc << endl;
	 

	
	return 0;
}
You should use std::getline instead of that strange while loop construct:
http://www.cplusplus.com/reference/string/string/getline/
http://en.cppreference.com/w/cpp/string/basic_string/getline

Or, you know, you could read each word separately...
Last edited on
Topic archived. No new replies allowed.