I was asked to make a program that reads a cin could be text and then counts the words in it(i need to count as a word every name that can be accepted as a variable name ex \_a,a1) my problem is that my code works for only one byte. if its more than one the sum is always 0.The only thing i think i can have wrong is that i didn't put the string into an array but a friend of mine told me i don't need to do so.below is my code:

```
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
    int sum=0;
    bool z= false;  //z is just a switch to see if we are inside a word\n
    string s;
    cout<<"Insert text: ";
    getline(cin,s);         //here we get the string\n
    int n=s.length()-1;     //for some reason i==(s.length-1) put a warning$
    for(int i=0;i==n;i++){  //here we check each byte to see what it contai$
            cout<<s[i];
            if(isalpha(s[i]) || s[i]=='_'){ //to enter a word we need a let$
                    z=true;
                    sum++;}
            if(z==true){    // if we are in a word we can have numbers as w$
                    if(!isalnum(s[i]) && s[i]!='_'){
                            z=false;}}      // exit the current word and go$
            if(s[i]==EOF){                  // the end\n
                    break;}}
    cout<<"Number of words is: "<<sum<<endl;        // the real end\n
return 0;
}

```