I have this Word Count feature on my revision program I have created.
I developed it to be able to count a sentance up to one full stop and it works perfectly to do that. However, I have decided I would like it to count how many words a user types in a whole paragraph, allowing them to use full stops, question marks & other punctuation.
Here is my code so far:
CODE
void wordCounter(int& keyPressed, int& currentMonth, int& currentYear)
{//start of 'wordCounter' function to allow the user to count the number of words they have typed
int getKeyPress();
char letter;
int numberOfWords = 0;
Gotoxy(0, 22);
SelectTextColour( clDarkGrey);
cout << "To go back to the menu, press the 'M' key at any time.";
Gotoxy(6, 6);
SelectTextColour( clGrey);
SelectBackColour( clBlack);
cout << "Please type in a sentance & press the 'Enter' key:";
Gotoxy(6, 9);
SelectTextColour( clWhite);
cin.get( letter);
while ( letter != '.')
{
if ( letter == ' ')
{
numberOfWords = numberOfWords + 1;
}
cin.get( letter);
}
if ( numberOfWords > 0)
{
numberOfWords = numberOfWords + 1;
Gotoxy(6, 19);
SelectTextColour( clGrey);
SelectBackColour( clBlack);
cout << "Thank you. The number of words you have entered is ";
SelectTextColour( clDarkCyan);
cout << numberOfWords;
}
keyPressed = getKeyPress();
if (keyPressed == 'M')
{
displayMenu(keyPressed, currentMonth, currentYear);
displayHeaderFooter(currentMonth, currentYear);
}
while(!_kbhit());
}//end of 'wordCount' function
I know it may seem simple to others, but I am a real beginner lol & cannot seem to understand how I would get this to count the number of words past the full stop. I think it may have something to do with this line:
CODE
while ( letter != '.')
in the while statement, but I can't tell what?
Thank you in advance.
Calum.
----------------
Now playing on iTunes:
All-4-One - I Swearvia
FoxyTunes