Experiencing Function Call problems for output

I am trying to get a program that counts the number of lowercase vowels in a string and outputs the number of each vowel individually.

So far, my code is a collection of thoughts and ideas from the book I'm reading/learning from. However, I think I have put something together wrong in either my function or MAIN.

My code runs up to the entry of the string of char's, but my function is not executing.

Beginner here, but trying to grasp this idea from this simple coding.


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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Exercise.21 Week 5 Programming
//This program counts the number of lowercase vowels
//in a string entered by the user. The counting is done
//by calling a function.

#include <iostream>
#include <cstring>
#include <istream>

int vowelFunct(char string[80]);//counting function

using namespace std;

int main()
{
	char string[80];

	cout << "Please enter a string of lowercase letters \n"
		 << "with or without spaces. It can be actual words, \n"
		 << "or just a jumble of letters.\n";
	cin.getline(string, 80);
	cout << "You entered " << string << endl;


	vowelFunct(string);//counting function call

	return 0;
}


int vowelFunct(char string[80])//counting function
{

	int a = 0;
	int e = 0;
	int i = 0;
	int o = 0;
	int u = 0;



	while (string != '\0')
	{
		switch (string[80])
		{
		case 'a':
			++a;
			break;
		case 'e':
			++e;
			break;
		case 'i':
			++i;
			break;
		case 'o':
			++o;
			break;
		case 'u':
			++u;
			break;
		}
	}

	cout << "There were " << a << " A(s).\n";
	cout << "There were " << e << " E(s).\n";
	cout << "There were " << i << " I(s).\n";
	cout << "There were " << o << " O(s).\n";
	cout << "There were " << u << " U(s).\n";

	return 0;
}	


My output ends with the return of the string, let's say "aeiou" for just an example.

Appreciate the help.
In your vowelFunct(), you are not moving over each character.

You will need either an index into your array of characters, or a pointer to the start of the array and increment the index or pointer after you have compared the character to which it addresses (or points).
Topic archived. No new replies allowed.