trying to decide which loop/s to use

Hi, I am pretty new to C++. I am currently taking my first course in it in college. I know how to get input and display output etc. We are now learning loops and I'm having trouble figuring out which loop to use (for/while). The program I am supposed to write gets two integers from the user and then displays the sum of only the even integers, between and including the two numbers entered by the user. So for example, if the user enters 2 & 7....the sum would be 12 (2 + 4 + 6). Can someone tell me which type of loop I should be using? Or how do I separate just the even numbers? That's were I'm stumped...
In this case (and in most others) it doesn't really matter whether you use a for or a while loop. Though a for loop would probably be better here.
Hint: The % operator gets the remainder of a division with rest (ex: 5%3 is 2, 6%3 is 0)
Hint2: The number following an uneven number is a even number.
Hint3: The second number after an even number is another even number.
Well, you gave me a starting point..hanst99. Thank you! So here's my code..


#include <iostream>
using namespace std;

{
int num1 = 0;
int num2 = 0;
int sum = 0;
int highestNum = 0;



cout << "Enter first integer: ";
cin >> num1;
cout << "Enter second integer: ";
cin >> num2;

if (num1<num2)
{
highestNum = num2;
}

else
{
cout << "ERROR!";
}

if (num1 % 2 == 0)

{

for (int x = 1; x < highestNum; x =2;)
{

sum = num1 x;
cout << "Sum of even integers is: "; <<sum <<endl;
}
}
else if (num1 % == 1)
{
for (int x = 1; x < highestNum; x ;)
{
sum = num1 x;
cout << "Sum of even integers is: "; <<sum <<endl;
}

//system("pause")
return 0;
}


Keeps giving me these errors:
error C2447: '{' : missing function header (old-style formal list?)
fatal error C1004: unexpected end-of-file found

I know I am either missing or have too many {'s I think.. but I'm not sure which ones I need to take out..or If the code is just completely wrong..lol

Anybody got any more hints? :)
Topic archived. No new replies allowed.