#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
southernd0529 -4 Newbie Poster
Recommended Answers
Jump to Posti think his problem is that he has an urgency, but doesn't know what to do.
Jump to PostThe code compiles fine,
yeah.... incomplete stubs often do.
All 5 Replies
southernd0529 -4 Newbie Poster
tux4life 2,072 Postaholic
jephthah 1,888 Posting Maven
JugglerDrummer 0 Junior Poster
jephthah 1,888 Posting Maven
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.