/********************************************************************
* Name: Elaine Torrez
* Date: 2/21/2026
* Assignment: HW_5f – Recursive Vowel Counter
*
* Description:
* This program uses recursion to count the number of vowels
* in a c_string (null-terminated character array).
********************************************************************/
/* OUTPUT:
Enter a statement:
Say it ain't so Joe.
There are 7 vowels in the statement.
Press any key to continue . . .
*/
#include <iostream>
#include <cstring>
using namespace std;
// Function prototype
int countVowels(char statement[], int index);
int main()
{
// Declare c_string
char statement[20] = ""; // initialized with null
// Prompt user
cout << "Enter a statement:" << endl;
// Read input (including spaces)
cin.getline(statement, 20);
// Call recursive function
int totalVowels = countVowels(statement, 0);
// Output result
cout << "There are " << totalVowels
<< " vowels in the statement." << endl;
cout << "Press any key to continue . . .";
cin.get();
return 0;
}
// Recursive function to count vowels
int countVowels(char statement[], int index)
{
// Base case: stop at null character
if (statement[index] == '\0')
return 0;
// Check if current character is a vowel
char ch = statement[index];
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' ||
ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
return 1 + countVowels(statement, index + 1);
}
else
{
return countVowels(statement, index + 1);
}
}