0

When trying to compile it says error

error: use of undeclared identifier 'isVowel'; did you mean 'islower'?

#include <iostream>

#include <cstring>

using namespace std;

int main() {

char word[50];

int num = 0;

cout << "Enter word: ";

cin.getline(word,50);

for(int i=0; word[i]; ++i){

if(isVowel(word[i]))

++num;

}

cout<<"The total number of vowels are "<<num<<endl;



}

bool isVowel(char c){

if(c=='a' || c=='A')

return true;

else if(c=='e' || c=='E')

return true;

else if(c=='i' || c=='I')

return true;

else if(c=='o' || c=='O')

return true;

else if(c=='u' || c=='U')

return true;

return false;

}
  • 1
    Does this answer your question? [What is an 'undeclared identifier' error and how do I fix it?](https://stackoverflow.com/questions/22197030/what-is-an-undeclared-identifier-error-and-how-do-i-fix-it), in particular the "Use before declaration" section of the currently top-voted answer. – JaMiT Jan 25 '20 at 06:25
  • @molbdnilo Yes, my mistake! – Ted Lyngmo Jan 25 '20 at 12:54

1 Answers1

1

You need to prototype your function before you use it. Otherwise the compiler doesn't know it exists:

bool isVowel(char c); // A prototype of the function you will later call

int main () {
    //... Whatever code you're doing....


}

bool isVowel(char c) {
   // Actually implement it here.

}

  • 2
    Opinion: My preference is to define functions ahead of first use. I hate having to make two changes in the code where one will do. Part of this because I'm lazy and the other is it sucks when you inject an error by changing only one of the two. – user4581301 Jan 25 '20 at 06:30
  • Oh Okay that makes sense! Thank you so much! – Cindy Lara Jan 25 '20 at 06:31