Hello
Please help. I am having a hard time making the leap from where I am to then picking out numbers (in this instance adding even numbers). Any suggestions or pointers would be greatly appreciated.
#include <iostream>
using namespace std;
// program computes the sum of all even numbers from input number
int compute_sum(int n);
int main()
{
int n;
cout << "enter a number" << endl;
cin >> n;
if (n % 2 == 0)
cout <<"even "<<compute_sum(n)<< endl;
else
cout << "odd " << endl;
return 0;
// return ((n & 1) == 1); // odd
// return ((n & 1) == 0); // even
}
int compute_sum(int n)
{
int count = 1;
int sum = 0;
while (count <= n)
{
sum = sum + count;
count = count + 1;
}
return sum;
}