I am not able to understand what is problem in this code why it is failing test-case and test_case 4 as i have used continue statement to skip the repeated if case

int main()
{
char ch[20];
cin.getline(ch,20);
int i=0;
while(ch[i]!=’\0’)
{
if(ch[0]==β€˜9’)
{i++;continue;}

	 if(ch[i]-'0'>=5)
	{
		int temp=ch[i]-'0';
		temp=9-temp;
		ch[i]=temp+'0';
		i++;continue;
	}
	i++;
	}
cout<<ch;

return 0;

}

Hey @Nidhi_Alipuria the problem is that if the first character of the string is 9 it’ll always go inside the first if statement in the while loop so rest of digits will not change. So your code your code’s solution to 98 would be 98 itself. In order to correct that we would only check ch[0] when i is 0. So,
if(ch[0] == '9')
will be replaced by
if(i == 0 && ch[0]=='9')

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.