hey can anyone help this is the code i have. i need to ouput the even and odd integers between two integers. i think what i have might work but when i run it it keeps running and never stops. also first num needs to be less then second anyone please help me

``````{
int firstNum, secondNum;
int firstNum_1, secondNum_1;
int sumOdd, sumEven;

sumOdd = 0;
sumEven = 0;
bool num0 = false;

while (!num0)
{
cout << "Please enter in a number: ";
cin >> firstNum;
cout << "Plese enter a second number: ";
cin >> secondNum;
if (firstNum <= secondNum)
{
num0 = true;
}
else if (firstNum > secondNum)
{
cout << "First number should be less than Second number" << endl;
}
}
firstNum_1 = firstNum;
secondNum_1 = secondNum;

while(firstNum != secondNum)
{
cout << "\n" << "Odd Numbers in between" << ' ' << firstNum << ' ' << "and" << ' ' << secondNum << ' ' << "is :" << ' ';
if((firstNum % 2) != 0)
{
cout << firstNum;
sumOdd += firstNum;
}
if(((firstNum % 2) != 0) && (firstNum != secondNum))
{
cout << ",";
}

while(firstNum_1 != secondNum_1)
{
cout << "\n" << "\n" << "Even Numbers in between" << ' ' << firstNum_1 << ' ' << "and" << ' ' << secondNum_1 << ' ' << "is :" << ' ';
if((firstNum_1 % 2) == 0)
{
cout << firstNum_1;
sumEven += firstNum_1;
}
if(((firstNum_1 % 2) == 0) && (firstNum_1 != secondNum_1))
{
cout << ",";
}
}
}``````

First of all please use code tags and proper indentation.

Check the exit criteria of the last two while loops.

Are you doing anything to modify the elements checked in the while condition?

Will the condition ever be false?

1. Use code tags
2. Looks like you never increase `firstNum` , so `while(firstNum != secondNum)` is always true.

Way way too complicated...

Input the two numbers like you did.
To print the even numbers, just use a for loop that goes from Number1 to Number2 incrementing i. If I%2....

Same with the odd numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.