Example: Let’s say your user input is 6. Then the number of sequences that sum up to 6 is 11 (including 6 itself). The problem I am having is that it works when the user enters 1 or 6, but if not it is way off and I can t figure out why.
I can give more info on the subject if needed.
#include <iostream>
using namespace std;
int sum(double number, int min, int & counter)
{
int temp=0, n;
n=number+temp;
if (number>=(n/2.0)+.5 && (number!=1))
{
number --;
temp ++;
while (number>=(n/2.0))
{
number --;
temp ++;
counter ++;
}
}
else if (number==1)
{
counter ++;
return 0;
}
sum(n-1, 1,counter);
return 0;
}
int main()
{
int counter=1;
double number;
cout << "-------------------------------------------------------
"
<< "Please enter the number: ";
cin >> number ;
cout << "
";
if (number!=1)
{
sum(number, 1, counter);
}
cout << "The total number of combinations that result in a sum of "
<< number << " is: " << counter
<< "
-------------------------------------------------------
";
return 0;
}