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
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.