What's wrong with this? (Counting number of words in a sentence)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
  string sentence;
    char let;
    getline(cin, sentence);
    int countW;
   
     for (int i = 0; i < sentence.length(); i++) 
	{
		let=sentence.at(i);
        if (isspace(let))
            countW++;
    }
  	cout<<countW;
    return 0;
}
Topic archived. No new replies allowed.