Flesch bool

So I'm trying to write a program that counts the number of syllables, words, and sentences in a txt.file or any given input using boolean functions. I'm stuck on why the boolean functions wont work even if they have already been declared

Here's what I got:

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
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;


int numSyllables, numWords, numSentences;
int isalpha(int numWords);
char isSyllableStarting, isSyllableEnding, isWordStarting, isWordEnding, isSentenceStarting, isSentenceEnding;
bool inSyllable(int numSyllables), inSentence(int numSentences), inWord(int numwords);

int main (int argc, char*argv[]) {
char c;
ifstream infile;
infile.open(argv[1]);
	while (infile.get(c));
	
	numSyllables =0;
	numSentences =0;
	numWords =0;
	
	bool inSyllable(int numSyllables) ////function-defenition error
	{		
		if (numSyllables=='a'||numSyllables=='e'||numSyllables=='i'||numSyllables=='o'||numSyllables=='u'){
			return true;
	} else if (inSyllable = true && isSyllableEnding = true) {  
		
		numSyllables++;
		return false;
	}
	}
////////////////////////
	bool inSentence(<#int numSentences#>){ ///expected primary-expression before '<' token ?????
		if (numSentences == '.' || numSentences=='?'|| numSentences=='!'){
			return true;
	} 
	else if (inSentence =true && isSentenceEnding = true) {
				numSentences++;
		return false;}
	}
	/////////////////////
bool inWord(<#int numwords#>){ 
	if (numWors == isalpha(c)){
	return true;	
	}else if (inWord =true && isWordEnding = true){		
		return false;
	}
	}
	cout << "Sentences: "<< numSentences << endl;
	cout << "Words: " << numWords << endl;
	cout << "Syllables: " << numSyllables << endl;

	}

}
infile.close();
return 0; 
}
	   
	   
	   
	   
You can't declare functions inside of other functions, either put them above or below main.

On a different note make sure you are using == (comparison) for all of your if statement checks, you seem to be switching between that and =.
Alright, I changed where the bool functions where above the main code. Now I three set of code that look similar to this:

1
2
3
4
5
6
7
8
9
10
bool inSyllable(int numSyllables) ////function-defenition error
{		
	if (numSyllables=='a'||numSyllables=='e'||numSyllables=='i'||numSyllables=='o'||numSyllables=='u'){
		return true;
	} else if (isSyllableStarting == true && isSyllableEnding == true) {  
		numSyllables = 0;
		numSyllables++;
		return false;
	}///////WARNING
}

but they all have "control reaches end of non-void function.
Last edited on
There is just a warning there because if none of your if/else if statements are true the function wont return anything. You can add some sort of default return statement at the end of the function but if it will always pass one of them it isn't anything to get too worried over.
Topic archived. No new replies allowed.