recursive vowel counter

I need help adding a vowel counter to my recursive program which i completed, i have a small idea how to do it and i even tried it but its not working, i dont know if i have everything. Help is appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` ``````#include < iostream> #include using namespace std; void reverseDigits(char num[], char revNum[], int,int); int main() { char letters[10] = {' '}; char reverseletters[10] = {' '}; //int multiplier = 1; bool isNegative = false; cout << "Enter a string: "; cin >> letters; cout << endl; int len = strlen(letters); int ind = 0; reverseDigits(letters, reverseletters, len, ind); cout << letters << " after reversal = " << reverseletters << endl; // display vowel count cout << "There were "<< let << "vowels in the word."; system("pause"); return 0; } int reverseDigits(char num[], char revNum[],int len, int ind,char let) { if (len == 0) return; else { // if check for vowel if (let == 'a' || let == 'e' || let == 'i' || let == 'o' || 'u') len -= 1; revNum[ind] = num[len]; ind += 1; reverseDigits(num, revNum, len, ind); } } ``````
Everywhere where char[] is used: Why not use std::string?
Line 29: let was undeclared in main().
Line 35: Mismatch between the prototype on line 6 and the definition here (int return type, additional parameter).
Line 43: Oops. You were doing so well with chaining equality statements until the 'u'.

Note that this code will only check for lowercase vowels. It's case sensitive. I don't know if you intended that, but just in case.

-Albatross
Last edited on
Yes its intented for lower case, and how would i fix line 35?
Well, look at the declaration on line 6 and look at line 35, and iron out the differences. Choose whether you change the declaration to match the definition or the definition to match the declaration (I think you want this one, but I may be wrong).

-Albatross
ok im not having much luck heres what my program looks like now
here are my errors:
1>d:\cmpsc212\chapter7\chapter7\recursion.cpp(54): warning C4715: 'reverseDigits' : not all control paths return a value
1>d:\cmpsc212\chapter7\chapter7\recursion.cpp(22): error C4700: uninitialized local variable 'let' used
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````#include < iostream> #include using namespace std; int reverseDigits(char num[], char revNum[], int,int,char let); int main() { char let; char letters[10] = {' '}; char reverseletters[10] = {' '}; //int multiplier = 1; bool isNegative = false; cout << "Enter a string: "; cin >> letters; cout << endl; int len = strlen(letters); int ind = 0; reverseDigits(letters, reverseletters, len, ind,let); cout << letters << " after reversal = " << reverseletters << endl; // display vowel count cout << "There were "<< let << "vowels in the word."; system("pause"); return 0; } int reverseDigits(char num[], char revNum[],int len, int ind,char let) { if (len == 0) return let; else { // if check for vowel if (let == 'a' || let == 'e' || let == 'i' || let == 'o' || 'u') len -= 1; revNum[ind] = num[len]; ind += 1; reverseDigits(num, revNum, len, ind,let); } } ``````
Topic archived. No new replies allowed.