Why my code gives me wrong output

#include
using namespace std;
int main() {
int n;
int key;
cin>>n;
cin>>key;
int rem;
int count;
while(n<0){
rem=n%10;
n=n/10;
count=0;
if(rem==key){
count++;

	}

}
cout<<count;

return 0;

}

hey, sry for delayed replay. corrected code–>

#include<iostream>
using namespace std;
int main() {
	int n;
	int key;
	cin>>n;
	cin>>key;
	int rem;
	int count=0;
	while(n>0){
		rem=n%10;
		if(rem==key){
			count++;
		}
		n=n/10;
	}
	cout<<count;
	return 0;
}

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.