Thread: function isVowel

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    4

    function isVowel

    I have this code that I am having trouble trying to get working, I am new to programming and am having difficulty can someone help me get my function to work properly?

    I have to identify whether or not a vowel has been entered then once it has been entered I need to display the number of vowels in the sentence. I can't figure out the proper logic to do the count and display my output. I am following my chapter but I am obviously doing something very wrong. The comments were what my teacher said needed to be done. Can someone help me?



    #include <iostream>
    using namespace std;
    bool isVowel(char ch);




    int main()
    {

    char letter, quit;

    cout<<"Enter a sentence "<<endl;
    cin.get(letter); // use cin.get(letter); to store the character data in variable ch
    cout<<"There are "<<isVowel(letter)<<" vowels in this sentence. "<<endl;

    cout<<"Press any key to continue "<<endl;
    cin>>quit;

    // use cin.get(ch); to store the character data in variable ch
    return 0;
    }

    // add logic here to test if the character is a vowel
    // and if it is a vowel,then increment a counter

    bool isVowel(char ch)
    {
    if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' ||
    ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
    {
    return true;
    }
    else
    {
    return false;
    }
    }

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I'm not completely sure of what you want to be done, but I think you'll be needing some loops. Here's what I think you want to have happen:

    Code:
    while the user doesn't want to quit
    {
       Get a character
       if it's a vowel
          add it to the running total
       if it's the quit value
           end loop
    
        print sentence
       print running total
    }

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    63
    What I would do, is store the input into an array (of type char)

    I would then create a for loop as such:
    Code:
    for (int i=0; i<strlen((message)); i++) {
    if(message[i] == A || message[i] == I || etc) {
    // this character is a vowel
    number_of_vowels++;  // increment count for number of vowels
    }  // end if
    } // end for
    
    cout << "The number of vowels is " << number_of_vowels << endl;
    tweak code/complete as needed
    Last edited by Philandrew; 11-05-2004 at 12:05 AM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Behold, the power of the search button: Ta Dah! Ooo and Aah over Salem's solution.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM