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.
Count the Vowels
Collapse
X
-
Hi,
I think this program will satisfy your need.
Regards,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; }
M.Sivadhas.
Comment