Armstrong number

#include
#include
using namespace std;
int main() {
int n;
cin>>n;

int sum=0,fin=n;
int digits = 0;
int x =n;
while(x>0){
	if(x%10 >0){
		digits++;
	}
	x = x/10;
}
while(n>0){
	int last = n%10;
	sum += pow(last,digits);
	n /=10;
}
if (sum ==0){
	cout<<"false"<<endl;
}
else if(sum ==fin){
    cout<<"true"<<endl;
}
else{
	cout<<"false"<<endl;
}
return 0;

}

all test cases not working although geting the correct ans