Count of words.

Hi guys, basically, I don't know anything about programming, only the basics, and our professor is trying to make us this program which is a string, that would count the vowels, spaces, and words. If the vowels exceed five, it will reverse the sentence. I'm done with all of this except the COUNT OF WORDS.
Basically, the thing I did was to initialize word=1 and add one everything a space is detected. What if the user entered 2 spaces between two words, it will count 3 words instead of two. Anyone have a more good solution for this?


Last edited on
I didn't look at it because you didn't use code tags. If it runs and does what it is supposed to, then your good.

http://www.cplusplus.com/articles/z13hAqkS/

so you really should use code tags as SamuelAdams suggested.

Anyone have a more good solution for this?
count non space. Like so
1
2
3
4
5
6
7
8
9
if(whoisa[i]!=' '){
if(i > 0)
{
if(whoisa[i - 1]==' ')
word++;
}
else
word++;}
}

you might better use isspace():
http://www.cplusplus.com/reference/cctype/isspace/
coder777, sorry about that. about your solution,
it doesnt count the word accurately.
if(whoisa[i - 1]==' ')
word++;?? is that suppose to be space++?
Can i get a more better solution, please. I really need this. with my codes, cuz were required to write it this way, so i apologize.
it doesnt count the word accurately.
what makes you think it doesn't?
Did you check it

if(whoisa[i - 1]==' ')
word++;?? is that suppose to be space++?
No, I left out the space count
where am i suppose to put that code? coder777, im really sorry, im kinda stupid with programming. I tried putting it after space++, but it didnt work.
I also need the space count together with the word count.
Topic archived. No new replies allowed.