My code doesn't work

#include
#include
#include
using namespace std;
int main() {
string n;
cin>>n;
int currO = (int)n[0];
int alterO = 9 - (int)n[0];
if(alterO!=0 && alterO<currO) {
char nowO = (char)alterO;
n[0] = nowO ;
}

for(int i=1; n[i] ; i++) {
	int curr,alter;
	curr = (int)n[i];
	alter = 9 - (int)n[i];
	if(alterO<currO) {
		char now = (char)alterO;
		n[i] = now ;
	}
}
cout<<n;

}

@priyamthakuria27
There are lot of mistake. I am pointing them out. let say testcase is"4545" ,see (int)n[0] won’t give 4, it will give ASCII value of character β€˜4’ i.e 52. Then when you do alterO=9-(int)n[0], it would result in (9-52) which is negative number. and it’ll give wrong result.
To deal with this type of situation, you code should go like this
int currO = n[0]-β€˜0’;
int alterO = 9 - currO;
if(alterO!=0 && alterO<currO) {
char nowO = (char)(alterO+β€˜0’);
n[0] = nowO ;
}

Do the same operation inside for loop as well

what does the " -β€˜0’ " do?

@priyamthakuria27
inorder to get the integral value of ith index in the string we are using ASCII value. So difference of ASCII value of char(a) and β€˜0’ will give difference between them. let say char a=β€˜5’, so if we subtract β€˜0’ from it we will get int(5). This is because we are actually subtracting their ASCII values, So ASCII_value(β€˜5’) - ASCII_value(β€˜0’) = 53 - 48 = 5.
You can’t directly change char to int.