I've searched the archives, the web, and other Linux/Programming websites' forums and I haven't been able to find my answer. I am writing a program that uses functions for different tasks. The first task is to count the number of consonants in a string. I'm getting a compiler error: program.cpp:(.text+0x6b): undefined reference to `count_vowels(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
usingnamespace std;
int count_vowels(int,string);
int count_cons(int,string);
void strip_symbols(string);
void format_word(string);
int main()
{
int wordnum=0; //num of words
int vowelnum=0; //num of vowels
int consnum=0; //num of consonants
string word;
cin >> word;
while (!cin.eof())
{
//~~~~~~~~~~~~~~~~~~~~~COUNTING OPERATIONS ~~~~~~~~~~~~~~~~~~~~~
vowelnum = vowelnum + count_vowels(vowelnum,word);
consnum = consnum + count_cons(consnum,word);
//--------------------------------------------------------------
//--------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~~WORD CONVERSION SECTION~~~~~~~~~~~~~~~~~~
strip_symbols(word);
format_word(word);
cout << word << " ";
wordnum++;
cin >> word;
}
return 0;
}
int count_cons(int num,string text)
{
int i=0;
int wlen = text.length();
while (i<(wlen-1))
{
cout << text[i] <<endl;
i++;
}
return num;
}
I know that the above code will not complete the task of counting consonants, but if I can't write a simple function to do a simple action like above, I sure as heck won't be able to write the more complex task of counting consonants.
I have been at this for way too long... a few hours already just trying to figure out what the problem is. I fear it's something extremely simple or something that should pop out right before me.
I really, really will appreciate any help.
Wow, well I feel like a moron. I guess I didn't understand that it won't compile without having a definition.. I commented out vowel_num() and the other two functions I didn't define (yet), and all is well.