Sorry about the title of the thread, I was looking at the wrong problem. For our class, we're supposed to get a sentence from a user and output the number of three letter words entered. Here's what I have so far:
#include <iostream>
#include <string>
using namespace std;
void main()
{
string sent;
int j(0);
cout << "Enter your sentence: ";
getline(cin, sent);
for(int i = 0; i <= sent.length(); i++)
{
if(sent[i] == ' ' && sent[i+3] == ' ')
j++;
}
cout << "You have entered " << j << " three letter words." << endl;
return;
}
I'm not sure what I'm doing wrong.