#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
int words = 1;
string userString;
cout << "Enter the text you want this fancy Word counter to count: " << endl << endl;
getline(cin,userString);
for(i = 0; i < userString.length(); i++)
{
if(userString.at(i) == ' ')
words++;
}
if((isalnum(userString) == 0))
words--;
cout << "\nThere are " << words << " words in your text." << endl << endl;
return 0;
}
so thats what i got. as you can see it works with the minor exception of the 'isalnum' if statement. what i want to do is keep this little program from counting spaced punctuation marks like ". . . ! ! !" right now all of those are counted as words. not a real application you know :)
any direction would be most appreciated.
also i keep seeing threads that say you shou NOT use 'void main()' if there a link to an explanation to this. my instructor says it doesnt really matter... what gives?
thank you!