I have been trying to write a code that counts words and sentences, yet I do not think I have the right logic. I need to write code only using beginner principles like using loops and functions, not vectors.
I have this code, but I need help trying to write this code not using vectors and only using very basic code.
I'd recommend looking one ahead, not one behind. When your program starts, you'll be searching in sentence[-1].
Also, I admire that you tried to separate your code from the rest of your text. Just so you know, we have [code] tags that do this for you AND put in all the fancy formatting.
Also, it might be worth considering the case where 'sentence' contains no words (is empty). This might be a rare case depending on the usage of your program, but a simple check beforehand can eliminate this problem:
1 2 3
int words = 0; //start at 0
if ( length > 0 ) //if there is something in the string, it must have a length > 0
words++; //we have one additional word