1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
void getNumber(int &num);
void analyzeNumber(int &num, int &evenSize, int &oddSize, int &zeroSize);
void printResults(int num, int evenSize, int oddSize, int zeroSize);
int main()//int argc, char** argv)
{
int num_size, numOfEven = 0, numOfOdd = 0, numOfZero = 0, num;
std::cout << "How many intergers do you want to classify? ";
std::cin >> num_size;
for (int repeat = 0; repeat < num_size; repeat++)
{
getNumber(num);
analyzeNumber(num, numOfEven, numOfOdd, numOfZero);
}
printResults(num, numOfEven, numOfOdd, numOfZero);
system("pause");
return 0;
}
void getNumber(int number)
{
std::cout << "\nEnter an interger number: ";
std::cin >> number;
//return number;
}
void analyzeNumber(int &num, int &evenSize, int &oddSize, int &zeroSize)
{
if(num!=0)
{
if((num%2) ==0)
evenSize++;
else
oddSize++;
}
else
{
zeroSize++;
}
}
void printResults(int num, int evenSize, int oddSize, int zeroSize)
{
std::cout << "The numbers typed: " << num << "\n";
std::cout << "Number of even: " << evenSize << std::endl;
std::cout << "Number of odd: " << oddSize << std::endl;
std::cout << "Number of zero: " << zeroSize << std::endl;
}
|