If you combined your both functions, you would get one working function :P
Firstly: why are you using your own numbers in totalEven? You don't use x and y at all; and you should use them!
Also, == is how you check if one variable is equal to other in C++. = is used for defining variable(like x = 10; it's a statement. But x==10 is a question).
Now, in second function you created loop nearly correctly; you don't have to always initialize something in for loop. Also, inside body of for loop, you didn't include anything, and it would be infinite loop, because you incremented some non-existing variable sum(have you tried compiling it?).
totalEven would look like this:
1 2 3 4 5 6 7 8 9 10
|
int totalEven(int x, int y)
{
int sum = 0;
for(x = x+1; x < y; ++x )
{
if( x % 2 == 0)
sum += x;
}
return sum;
}
|
My method takes all numbers between x and y, but not x or y.
So if you want to check for sum of even numbers between 3 and 4, my program would output 0 - even though 4 is even, program checks numbers BETWEEN(and between 3 and 4 you don't have any integer :) )
Hope it helped. Try to write totalOdd basing on knowledge you gained. If you do not understand my function, try to explain to yourself step by step what this function does, and if you do not know some particular step - ask.
Cheers!