Have you debugged your code. You are getting only first word by cin>> Phrase; statement.
Why this is happening? Oh Cin delimits the string by SPACE . Ok, so
You need to get whole line first. Than search all space and count all words i.e. no of space + 1
use getline() and istringstream and your problem should be solved.
look as far as u have a problem of counting words in your phrase then a solution to your problem is "just count the number spaces in your phrase and add 1 in it". for example in phrase "I Love Programming" there are 2 space characters. 1 after I and 2nd after Love + 1 for last word. so u will get answer 3.
1 more very good solution is use "strtok" and tokenize your phrase on space character. then just count the number of tokens.
i think second solution is better than the first one.
//Get the user to enter a sentence
cout<<" Please enter a sentence.\n";
cout<<" The number of words in your phrase is "
If you are ONLY looking for words, not the entire string length, then Phrase.length() won't work because it includes spaces. Pseudocode:
1) User enters string
2) Look for letters only which indicates program is in the middle of a word
3) If space is encountered, ignore it and consider one word in the string to be counted.
4) repeat until end of string