I'm have a really hard time with this program and am totally lost. I'm trying to write a program that reads a set of integers and then finds the sum of the even and odd integers. So far this is all I have come up with, but I'm sure it's wrong.
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
using namespace std;
const int N = 20;
int main()
{
int counter;
int number;
int even;
int odd;
double sumEven;
double sumOdd;
ifstream infile;
infile.open("C:\\input.txt");
for (counter = 1; counter <= N; counter++)
{
cin >> number;
sumEven = even + number;
switch (number % 2)
{
case 0: even++;
case 1:
case -1: odd++;
}
}
cout << endl;
cout << "EvenOdd output by " << endl;
cout << "Number of values in file: " << number << endl;
cout << "Number of even values: " << even << endl;
cout << "Sum of even values: " << sumEven << endl;
cout << "Number of odd values: " << odd << endl;
cout << "Sum of odd values: " << sumOdd << endl;
system("PAUSE");
return 0;
}
Code tags added. -Narue