Discussion in 'C++' started by siddhartha.chadha@gmail.com, Mar 11, 2006.

1. ### Guest

I wanted to write a code to calculate the number of words containing
vowels in a given set....if you find the error please reply at

# include <iostream>
using namespace std;

int main ()
{
char input;
float vowel = 0; float words = -1;
float percent;
for ( ; cin >> input ; )
{ //if ( input == '.' ) {break;}
//if ( input == ' ') { words ++; continue ;}
if ( input == 'a' || input == 'e' || input == 'i' || input == 'o'
|| input =='u')
{ vowel ++; }
if ( input == '.') {break;}
if ( input != 'a' || input != 'e' || input != 'i' || input !=
'o' || input !='u')
{ continue; }
}
cout << words << " " << vowel ;

percent = (vowel/words) * 100;
cout << endl <<percent;

int i ;
cin >> i;
return 0;
}

, Mar 11, 2006

2. ### MoonlitGuest

Hi,

if ( input != 'a' || input != 'e' || input != 'i' || input !=
'o' || input !='u')
{ continue; }
}

Now look at that line closely when will the condition be false?

--

Regards, Ron AF Greve

http://moonlit.xs4all.nl

<> wrote in message
news:...
>I wanted to write a code to calculate the number of words containing
> vowels in a given set....if you find the error please reply at
>
>
> # include <iostream>
> using namespace std;
>
> int main ()
> {
> char input;
> float vowel = 0; float words = -1;
> float percent;
> for ( ; cin >> input ; )
> { //if ( input == '.' ) {break;}
> //if ( input == ' ') { words ++; continue ;}
> if ( input == 'a' || input == 'e' || input == 'i' || input == 'o'
> || input =='u')
> { vowel ++; }
> if ( input == '.') {break;}
> if ( input != 'a' || input != 'e' || input != 'i' || input !=
> 'o' || input !='u')
> { continue; }
> }
> cout << words << " " << vowel ;
>
> percent = (vowel/words) * 100;
> cout << endl <<percent;
>
> int i ;
> cin >> i;
> return 0;
> }
>

Moonlit, Mar 11, 2006

3. ### Ivan VecerinaGuest

<> wrote in message
news:...
:I wanted to write a code to calculate the number of words containing
: vowels in a given set....if you find the error please reply at
:

It is against this newsgroup's policy to provide answers by email.

You seem to be counting vowels instead of counting words that contain
vowels. You could try to set a flag (bool hasVowel) whenever a vowel
is encountered, then when the end of a word has been found:
{ ++words; if(hasVowel) { ++vowelWords; hasVowel=false; } }

Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com

Ivan Vecerina, Mar 11, 2006
4. ### MoonlitGuest

Besides that.

To make your life (assignment) eassier look into string and
string.find_first_of:

http://www.sgi.com/tech/stl/basic_string.html

don't forget to include <string>

--

Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Moonlit" <news moonlit xs4all nl> wrote in message
news:4412cf35\$0\$11064\$4all.nl...
> Hi,
>
> if ( input != 'a' || input != 'e' || input != 'i' || input !=
> 'o' || input !='u')
> { continue; }
> }
>
>
> Now look at that line closely when will the condition be false?
>
> --
>
>
> Regards, Ron AF Greve
>
> http://moonlit.xs4all.nl
>
> <> wrote in message
> news:...
>>I wanted to write a code to calculate the number of words containing
>> vowels in a given set....if you find the error please reply at
>>
>>
>> # include <iostream>
>> using namespace std;
>>
>> int main ()
>> {
>> char input;
>> float vowel = 0; float words = -1;
>> float percent;
>> for ( ; cin >> input ; )
>> { //if ( input == '.' ) {break;}
>> //if ( input == ' ') { words ++; continue ;}
>> if ( input == 'a' || input == 'e' || input == 'i' || input == 'o'
>> || input =='u')
>> { vowel ++; }
>> if ( input == '.') {break;}
>> if ( input != 'a' || input != 'e' || input != 'i' || input !=
>> 'o' || input !='u')
>> { continue; }
>> }
>> cout << words << " " << vowel ;
>>
>> percent = (vowel/words) * 100;
>> cout << endl <<percent;
>>
>> int i ;
>> cin >> i;
>> return 0;
>> }
>>

>
>

Moonlit, Mar 11, 2006
5. ### osmiumGuest

<> wrote:

>I wanted to write a code to calculate the number of words containing
> vowels in a given set....if you find the error please reply at

I know of only one possible word in English that has no vowel. Many people
claim that ms is a word; if you buy into that notion I don't) , the fraction
is 1/ number of words in the English language.

osmium, Mar 11, 2006
6. ### MoonlitGuest

--

"osmium" <> wrote in message
news:...
> <> wrote:
>
>>I wanted to write a code to calculate the number of words containing
>> vowels in a given set....if you find the error please reply at

>
> I know of only one possible word in English that has no vowel. Many people
> claim that ms is a word; if you buy into that notion I don't)

Lol, good one
> , the fraction is 1/ number of words in the English language.
>
>
>

Regards, Ron AF Greve

http://moonlit.xs4all.nl

Moonlit, Mar 11, 2006
7. ### Andrew KoenigGuest

"osmium" <> wrote in message
news:...

> I know of only one possible word in English that has no vowel.

crwth: A bowed Welsh lyre played from the European Middle Ages to about
1800. It was about the size of a violin. Though originally plucked, it was
played with a bow from the 11th century, and a fingerboard was added behind
the strings in the last part of the 13th century.

Andrew Koenig, Mar 11, 2006
8. ### PhlipGuest

Andrew Koenig wrote:

>> I know of only one possible word in English that has no vowel.

>
> crwth: A bowed Welsh lyre played from the European Middle Ages to about
> 1800. It was about the size of a violin. Though originally plucked, it was
> played with a bow from the 11th century, and a fingerboard was added
> behind the strings in the last part of the 13th century.

The vowels are AEIOU, sometimes Y and sometimes W.

You will also find "cwm", which is a variation of "coomb", a steep valley
high in the mountains. (Cf Tolkien's Deeping Coomb.)

I once slaughtered a 6th-grade class in Hangman with that one. ;-)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!

Phlip, Mar 11, 2006
9. ### Ivan VecerinaGuest

"Phlip" <> wrote in message
news:vIDQf.19651\$...
: Andrew Koenig wrote:
:
: >> I know of only one possible word in English that has no vowel.
: >
: > crwth: A bowed Welsh lyre played from the European Middle Ages to
: > 1800. It was about the size of a violin. Though originally plucked, it
was
: > played with a bow from the 11th century, and a fingerboard was added
: > behind the strings in the last part of the 13th century.
:
: The vowels are AEIOU, sometimes Y and sometimes W.

The OP did not specify that the words were in English.
In some slavic languages, e.g. Croatian, R is used
as a vowel, leading to words such as prst (finger)
or stvrdnuti (solidify) -- which I find cute.

Even in English, many abbreviations and acronyms have
made it into the dictionary ( mph, mm, ccw... ), and
definitely could be found in a source text.

--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Ivan Vecerina, Mar 11, 2006
10. ### Len PhilpotGuest

Andrew Koenig said the following on 3/11/2006 11:19 AM:
> "osmium" <> wrote in message
> news:...
>
>> I know of only one possible word in English that has no vowel.

>
> crwth: A bowed Welsh lyre played from the European Middle Ages to about
> 1800. It was about the size of a violin. Though originally plucked, it was
> played with a bow from the 11th century, and a fingerboard was added behind
> the strings in the last part of the 13th century.

Then again, with names like
Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch, does Welsh
actually qualify as English? (or American, for that matter

I grant you there are some vowels in there, if you search diligently
enough... Although as a single language American, I'm in no position to
question things I suppose. Like the old joke goes :

Q. What do you call a German who also speaks French & Italian fluently?
A. Multi-lingual

Q. What do you call a man who speaks Spanish & Portugese fluently?
A. Bi-lingual

Q. What you do call a man who speaks English poorly?
A. An American

--

---- Len Philpot --------
------- ><> ------------- http://members.cox.net/lenphilpot/

Len Philpot, Mar 11, 2006
11. ### osmiumGuest

"Andrew Koenig" wrote:

> "osmium" <> wrote in message
> news:...
>
>> I know of only one possible word in English that has no vowel.

>
> crwth: A bowed Welsh lyre played from the European Middle Ages to about
> 1800. It was about the size of a violin. Though originally plucked, it was
> played with a bow from the 11th century, and a fingerboard was added
> behind the strings in the last part of the 13th century.

Remarkable! So I had a hundred percent error in my post, there are *two*
words. I looked it up in my unabridged MW 3rd edition, and there it was! I
have never heard, until today, of the escape rules for 'W' mentioned

osmium, Mar 11, 2006
12. ### PhlipGuest

osmium wrote:

> Remarkable! So I had a hundred percent error in my post, there are *two*
> words. I looked it up in my unabridged MW 3rd edition, and there it was!
> I
> have never heard, until today, of the escape rules for 'W' mentioned

If you mean my rules, I made them up. (-;

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!

Phlip, Mar 11, 2006
13. ### NoclambulistGuest

Why do you use float words = -1;
not int words = -1;

Noclambulist, Mar 12, 2006
14. ### Default UserGuest

Noclambulist wrote:

> Why do you use float words = -1;
> not int words = -1;

Who? What? (see below)

Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded