Keep getting this error..

I keep getting this error, although I'm not sure why

"hw3.cpp:7:1: error: expected initializer before 'int'
int num_vow (char ch, int vow){ "

Here's my code:

int main()

int num_vow (char ch, int vow){
while (ch != '!'){
if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){
vow ++;}
cin.get(ch);
}
return (vow);
}

int vow = 0, num_vow(char, int);
char ch;

cout << "Enter lines of text terminated with a '!'.\n";
cin.get(ch);
vow = num_vow (ch, vow);

cout << "There are " << vow << " vowels in the text.\n";
}
return 0;

Please use code tags for your code to make it more readable - http://www.cplusplus.com/articles/jEywvCM9/

A lot of errors here. First of all, main is missing brackets

1
2
3
4
int main()
{ // this is missing

}


Second, function shouldnt be inside main, put it above.

Third, || ch 'I' || should be: ch == 'I'
Full program:


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
#include <iostream>

using namespace std;

int num_vow(char ch, int vow){
	while (ch != '!'){
		if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){
			vow++;
		}
		cin.get(ch);
	}
	return (vow);
}


int main()
{
	int vow = 0, num_vow(char, int);
	char ch;

	cout << "Enter lines of text terminated with a '!'.\n";
	cin.get(ch);
	vow = num_vow(ch, vow);

	cout << "There are " << vow << " vowels in the text.\n";
	return 0;
}
Topic archived. No new replies allowed.