Sum of even and odd places

i have written the code and i cant figure out why all the test cases are not working
please check my coding part
#include
using namespace std;
int main() {
int x,n;
cin>>x;
n=x;
int even=0;
int odd=0;
int count=0;
while(x!=0){
count++;
x=x/10;
}

if(count %2 ==0){
   while(n!=0){
	   even = even + n%10;
	    n= n/10;
	   odd = odd + n%10;
	   n= n/10;
	  
       
   }
    
}
	

else{
	while(n!=0){
		odd = odd +n%10;
		n= n/10;
		even = even + n%10;
		n=n/10;

	}
		
	
}

cout<<odd<<endl;
cout<<even;
return 0;

}

The logic error is in how digits are added to odd and even . The digit placement for odd and even sums is incorrect because you’re not properly managing the alternating digits.

You can refer my code as well

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.