Hi. I appreciate your time and help. I am to write a program that takes numbers from a file and adds up the even and odd integers. I can get the first while statement to produce the correct numbers, but I cannot for the second. I'm not sure where I am going wrong. Here is the code:
inFile >> num;
while (num !=-999 && (num % 2 ==0))
{
eSum = num + eSum;
inFile >>num;
}
cout <<"Summation of even numbers: " <<eSum <<endl;
while (num !=-999 && (num % 2 !=0))
{
oNum = num + oNum;
inFile >> num;
}
cout <<"Summation of odd numbers: " <<oSum <<endl;
cout << endl;
What are you using for an input file? Because by all rights this code shouldn't work properly for the even numbers. You need an if statement within your loops to check even/oddness of your numbers and your while loops need to NOT have the second condition.