#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;

const int N = 20;

// file declaration and open
ifstream inFile;
ofstream outFile;
/*
need to open files here
*/

//function prototypes
void initialize(int& zeroCount, int& oddCount, int& evenCount);
void getNumber(int& num);
void classifyNumber(int num, int& zeroCount, int& oddCount, int& evenCount);
void printResults(int zeroCount, int oddCount, int evenCount);

int main()
{
    //variable declcaration
    int counter;
    int number;
    int zeros;
    int odds;
    int evens;
    
    initialize(zeros, odds, evens);
    
    cout<<"Please enter " << N << " integers."<<endl;
    cout<<"The numbers you entered are: "<<endl;
    
    for (counter=1; counter <= N; counter++)
    {
        getNumber(number);
        cout<<number<<" ";
        classifyNumber(number,zeros,odds, evens);
    } // end of for loop
    
    cout<< endl;
    printResults(zeros,odds,evens);
    
    inFile.close();
    outFile.close();
    system("PAUSE");
    return 0;
}

void initialize(int& zeroCount, int& oddCount, int& evenCount)
{
    zeroCount = 0;
    oddCount = 0;
    evenCount = 0;
}

void getNumber(int& num)
{
    cin>>num;
}

void classifyNumber(int num, int& zeroCount, int& oddCount, int& evenCount)
{
    switch(num%2)
    {
        case 0:  evenCount++;
                if (num == 0)
                  zeroCount++;
                break;
        case 1:
        case -1: oddCount++;
    } // end of switch
} // end classifyNumbe

void printResults(int zeroCount, int oddCount, int evenCount)
{
    cout<<"There are "<<evenCount << " evens, "
        <<"which includes "<<zeroCount<<" zeros"<< endl;
    cout<<"The number of odd numbers is: "<< oddCount<<endl;
} // end printResults

Recommended Answers

All 5 Replies

i have to modify the GETNUMBER function so that it gets the number from the file and reads it

Please post using code tags, by the way: what's your problem as you didn't tell me :) ...

i think his problem is that he has an urgency, but doesn't know what to do.

The code compiles fine,

yeah.... incomplete stubs often do.

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.