0

Hi everyone!I've started to learn C++ couple of months ago and having some trouble with the code i'm trying the write.. I have to write a function that converts every digit of the parameter to zero,except 2.And number of digits is unknown..

I made this but its's output is always 0.Even i enter a number that contains 2...I'll be glad if you could help..Thanks:)

```
#include<iostream>
using namespace std;
int convertNum(int n){
int digits=0;
int remainder;
for(int i=n;n!=0;n/=10)
digits=digits+1;
for(int j=1;j<=digits;j++){
n=n/10;
remainder=n%10;
if(remainder==2)
remainder=2;
if(remainder!=2)
remainder=0;
}
return remainder;
}
int main()
{
int a;
cout<<"Please enter a positive integer"<<endl;
cin>>a;
cout<<"The converted version of "<<a<<" is ----> "<<convertNum(a);
return 0;
}
```