Why isn't my code giving me error

I have done the same code along but i am getting a wrong output

#include
using namespace std;

int main(){
int digits = 0;
int alphabets = 0;
int spaces = 0;
int other = 0;

char ch;
ch = cin.get();

while(ch != '$'){
    if(ch >= '0' and ch <= '9'){
        digits++;
    }
    else if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')){
        alphabets++;
    }
    else if(ch == ' ' or ch == '\n' or ch == '\t'){
        spaces++;
    }
    else{
        other++;
    }

    ch = cin.get();
}
cout<<"Digits "<<digits<<endl;
cout<<"Alphabets "<<alphabets<<endl;
cout<<"Spaces "<<spaces<<endl;
cout<<"others "<<other<<endl;


return 0;

}

hi… ur code is working perfectly fine https://ide.codingblocks.com/s/594134
input --> hello world 1001@!$
ur o/p
image
ur code is fine

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Ohh ok thank you sir!