Count the Vowels

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sevendash
    New Member
    • Nov 2006
    • 1

    Count the Vowels

    I need to create a program that has the user input a sequence of variables, and counts the variables. What I can't get is how to get each character from the string, and have it checked by my function that will tell if it's a variable or not.
  • sivadhas2006
    New Member
    • Nov 2006
    • 142

    #2
    Hi,

    I think this program will satisfy your need.

    Code:
    #include <iostream.h>
    #include <string.h>
    
    #define VOWEL_CHARACTERS   "AEIOUaeiou"
    
    int main(int argc, char* argv[])
    {
       char
          szInput[100];  
          
       int
          nIndex = 0,
          nVowelsCount = 0,
          nStringLength = 0;
    
       cout << "****************** Count Vowels Characters ***********************\n";
    
       // Get the input.
       cout << "Enter the string : ";
       cin >> szInput;   
    
       // Get the length of the string.
       nStringLength = strlen(szInput);
       for(nIndex = 0; nIndex < nStringLength; nIndex++)
       {
          // Check whether it is a vowel character.
          if(strchr(VOWEL_CHARACTERS, szInput[nIndex]) != NULL)
          {
             // Increment the vowel characters count.
             nVowelsCount++;
          }      
       }
       // Print the result.
       cout << "The number of vowels characters present in the string " << szInput << " is " << nVowelsCount;
    
       return 0;
    }
    Regards,
    M.Sivadhas.

    Comment

    Working...