hello everyone.
here is my own first algorithm. it only counts the number of words in a line.
from my testings it works just fine.
let me know what you think and if there is a better way to write it.
Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
int wordCount = 0;
string words;
getline(cin, words);
int length = words.length();
for(int index = 0; index <= length; ++index){
while(words[index] != 32){
++index;
}
++wordCount;
while(words[index] == 32){
++index;
}
}
if(words[0] == 32)
--wordCount;
cout << wordCount << endl;
return 0;
}