I have designed the code perfectly but it is still not working
#include<iostream>
#include<cstring>
using namespace std;
int string_to_int(string s,int n)
{
//Base Case
if(n==-1)
{
return 0;
}
int d=s[n]-'0';
int sa=string_to_int(s,n-1);
return (sa*10+d);
}
int main() {
string s;
cin>>s;
int n=s.length();
int ans=string_to_int(s,n-1);
cout<<ans<<endl;
return 0;
}
Just made a few changes please check.