CSES-Digit Queries

I’m not sure what I’m missing in my code. I’ve first tried to get the number on digits in the answer number and then calculating the number based on the difference.

Can anyone please help?

Here is my code: 4juOWC - Online C++0x Compiler & Debugging Tool - Ideone.com

The third and fourth test cases are failing for me.