I'm having a bit of a hard time creating a function, using iteration, to find the sum of all even integers between 1 and the number the user inputs. The program guidelines require a function to solve this three ways; a formula, iteration, and recursion. This is what I have so far.
It is a bad idea to declare a function such a way when the function has return type void and at the same time has one "output" parameter. It is better to declare it returning a value. So instead of
Take into account that your original function does not work correctly if an argument is negative. So it is better to declare it having a parameter of type unsigned int.
As for the second function then it is very simple
1 2 3 4 5 6 7 8 9
unsignedint loopEvenSum( unsignedint num )
{
unsignedint evenSum = 0;
for ( unsignedint i = 2; i <= num; i += 2 ) evenSum += i;
return ( evenSum );
}