Chewbacca number

I am failing to add the case when first digit is 9…plz help me

include

using namespace std;

define int long long

int chewbaccanum(int n){
int no = 0,i=1;
while (n!=0)
{
int digit = n%10;
int newdigit = 9 - digit;
if (newdigit<digit)
{
if (0<n<10)
{
if (digit == 9 && newdigit == 0)
{
no += digit*i;
}

       }
       no += newdigit*i;
       
    }
    else
    {
        no += digit*i;
    }
    
   i *= 10;
   n /= 10; 
}
return no;

}

int32_t main(){
int n;
cin>>n;
cout<<chewbaccanum(n);
return 0;
}

kindly share the link of code so that i can modify and run your code

Logic:
if digit is >5 flip that digit otherwise don’t flip
also check some corner cases
a) first digit should not be zero so if first digit is 9 then it should remain unchanged
b) if number is 0 only then output should be 9, not 0.

Reference Code


here is the link to my code…please see it and change the error

code is not saved recheck the link

Modified Code

for input 999
you output 999
but correct output is 900
check the changes in modified code , you have done syntax error at line no 13

so basically it should not be 0<n<10…but why it is it so ???..isn’t both r same??

NO
this is not the correct syntax
correct one is
0<n && n<10

okie…thank you…i get it now

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.