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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include < iostream>
#include <cstring>

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include < iostream>
#include <cstring>

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.