[| -- C++ Help Please: Counting Vowels in a Given Text -- |]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HypeBeast McStreetwear
    New Member
    • Sep 2008
    • 20

    [| -- C++ Help Please: Counting Vowels in a Given Text -- |]

    Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u)

    For my test run I have to use "unquestionably ", but I can't anything to work. Here's what I have so far.

    Code:
    #include <iostream>
    #include <string>
    #include <cstring>
    
    using namespace std;
    
    void stringout();
    string input;
    
    int main()
    {
    
        cout << "Input a string of characters: " ;
        cin >> input;
        cout << "You entered: " << input << endl;
    
        stringout();
    
    
        return 0;
    }
    
    void stringout()
    {
        char ch;
        int vowel=0, consonant=0;
        int length = input.length();
    
        for (int i = 0; i < length; i++)
        {
            if ((ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u') ||
                (ch == 'A') || (ch == 'E') || (ch == 'I') || (ch == 'O') || (ch == 'U'))
                ++vowel;
        else
            ++consonant;
        }
        
    
        cout << "This has " << input.length() << " characters, " <<endl;
    }
    It keeps telling me to input a string of characters, but even when do put in "unquestionably " into the put space it doesn't help. Can anyone give me a hand, please?
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Originally posted by HypeBeast McStreetwear
    Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u)

    For my test run I have to use "unquestionably ", but I can't anything to work.

    It keeps telling me to input a string of characters, but even when do put in "unquestionably " into the put space it doesn't help. Can anyone give me a hand, please?
    Are you saying that all your program does is continuously print the following?
    Input a string of characters: unquestionably
    You entered: unquestionably
    Input a string of characters: unquestionably
    You entered: unquestionably
    Input a string of characters: unquestionably
    You entered: unquestionably
    ...


    Boy, I sure don't see why it would do that. Are you sure these are the symptoms? Can you provide a copy of what you see on your terminal?

    Comment

    • HypeBeast McStreetwear
      New Member
      • Sep 2008
      • 20

      #3
      Yea sure.

      [IMG][/IMG]

      Comment

      • boxfish
        Recognized Expert Contributor
        • Mar 2008
        • 469

        #4
        Just type in a string of characters when it says to. It should work fine. Except that if you are running this program from windows explorer or some such, it will probably close as soon as you press enter. If this happens, you can put a line of code at the end of your program that waits for some more input, but I've heard this is a bad thing to do. Two cin.get()s should work, but am I right that there is a good reason not to do this?
        Hope this helps.
        Edit:
        May I suggest making input an argument to stringout, instead of a global variable? Global variables are definitely a bad thing.

        Comment

        • AmeL
          New Member
          • Oct 2008
          • 15

          #5
          Yep you can prompt a user to press any key before exiting; yet you can launch your command prompt and execute your .exe to see what is displayed.
          However ( this is not what you asked for ), I found that your code does not really count the number of vowels or consonant of the inputted string from users. It had better that you redesign your code again to make it work as what is required.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            It sounds like you're uncertain of the purpose of the I/O commands between lines 13 and 15.
            What do you think those lines are trying to accomplish?

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              In function stringout, what is the purpose of variable ch?
              What is its value?

              Comment

              Working...