Compare and contrast:
#include <iostream>
using namespace std;
int main()
{
int even = 0, odd = 0;
int input;
cout<<"Enter a set of numbers: ";
while ( cin>> input ) {
if ( input % 2 == 0 )
even += input;
else
odd += input;
}
cout<<"Even: "<< even <<'\n'
<<"Odd: "<< odd <<endl;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>I have to use a for loop and then get the integers from a file
>created...which I have as named input.txt.
That's nice, but I wasn't doing your homework for you. I was giving you example code so that you can figure out what you're doing wrong.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401