I am trying to write code for homework that uses recursion and addition to multiply two integers. But at present, I am getting a lot of error messages, and I'm not even sure that I am on the right track. And, just for verification, it's recursive, isn't it? I wrote another program for this problem, which worked great until I realized that it was not really recursive. Here is the full code:
#include <iostream>
#include <iomanip>
using namespace std;
int result;
int m;
int n;
int rmultiply(int m, int n)
{
if(n > 1)
return(m + (rmultiply(n - 1)));
else if ((m == 0) || (n == 0))
return 0;
else if (n == 1)
return m;
}
int main(m, n)
{
cout << "Enter two integers to multiply" << endl;
cin >> m >> n;
result = rmultiply(m,n);
cout << result;
}
Mistake 1: Too few arguments for function 'int rmultiply (int, int)'
return(m + (rmultiply(n - 1)));
Warning: control reaches the end of a non-void function
Error 2 (for lines of code below): list of expressions processed as a compound expression in the initializer
Error 3: Expected ',' or ';' before the '{' token
:
int main(m, n)
{
!