Please help!!!!

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
    #1
    1. Advertising

  2. Moonlit Guest

    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
    #2
    1. Advertising

  3. Re: Please help!!!! [homework?]

    <> 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
    #3
  4. Moonlit Guest

    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
    #4
  5. osmium Guest

    <> 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
    #5
  6. Moonlit Guest

    --



    "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
    #6
  7. "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
    #7
  8. Phlip Guest

    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
    #8
  9. "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
    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.


    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
    #9
  10. Len Philpot Guest

    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
    #10
  11. osmium Guest

    "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
    up-thread.
    osmium, Mar 11, 2006
    #11
  12. Phlip Guest

    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
    > up-thread.


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

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
    Phlip, Mar 11, 2006
    #12
  13. Noclambulist Guest

    Why do you use float words = -1;
    not int words = -1;
    Noclambulist, Mar 12, 2006
    #13
  14. Default User Guest

    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
    header.
    Default User, Mar 12, 2006
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    7,968
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    506
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    550
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,746
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,100
Loading...

Share This Page