Multiplication using recursion

what is the error in this code
#include
using namespace std;
int multiply(int a, int b){
int ans;
if(a==0||b==0){
return 0;
}
else if(a==1){
ans = b;
return ans;
}
else if (b==1){
ans = a;
return ans;

}
else{
ans = a+multiply(a, b-1);
if(a>0&&b>0 || a<0&&b<0)
return ans;
else
return -ans;
}

}

int main(){
int a,b;
int c = multiply(-10,8);
cout<<c;

return 0;}

You can recheck the logic from here.If still there are some errors with your code then please save your code on ide.codingblocks.com and then share its link.

please check the conditions for negative result if one of the number is negative in my code

You can set a check earlier in the code.
Something like this:
Given two numbers a and b
int sign=1;
if(a<0&&b>0||a>0&&b<0)
sign=-1;

then change a and be to their positives:
a=abs(a);
b=abs(b);

At the end multiply the result with sign.

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.