# Simple problem just can't seem to get it

This is a discussion on Simple problem just can't seem to get it within the C Programming forums, part of the General Programming Boards category; How do you get the sum of all numbers that are less than a max value and either even or ...

1. ## Simple problem just can't seem to get it

How do you get the sum of all numbers that are less than a max value and either even or odd? I know that I am not supposed to ask to have assignments done for me but this is not the whole program i just need the basic idea of how to get all of the even or odd numbers up to that certain number. I am sorry if this question isn't clear.
~Sven

2. As this is homework, I wrote an example in c++ rather then c

Code:
```#include <iostream>

int main()
{
int MAX = 7;
bool evens = false;
int sum = 0;
int i = 1;
if (evens)
i++;
for (; i <= MAX; i=i+2)
sum += i;
std::cout << sum;
}```
Notes
How do you get the sum of all numbers that are less than a max value and either even or odd?
The sum is infinite, likewise the sum of all integers is also infinite. You are interested in whole numbers.

And I encourage you to not do this using brute force (the way I showed). There is a much more elegant way involving the averages of a set of numbers [Guass did this]

3. Code:
```if( x < y )
if odd