Mar 16, 2012 at 11:43am UTC
Write a program that consists of a named checkNum that takes as a parameter an integer (as a long value) and returns the number of odd, even, and zero digit.
i have no idea what's the output of this question wanted..
hope someone can help me,
thx
Mar 16, 2012 at 12:18pm UTC
Take a number. For example, 12345543210043
How many odd numbers are in that? 7. They are 1,3,5,5,3,1 and 3.
How many even numbers are in that? 5. They are 2,4,4,2 and 4.
How many zeroes are in that? 2.
Mar 16, 2012 at 1:04pm UTC
#include <iostream>
using namespace std;
const int N = 20;
void getNum(int& num);
void checkNum (int num, int& oddCount, int& evenCount, int& zeroCount);
void printResults(int zeroCount, int oddCount, int evenCount);
int main()
{
int number, odds, evens, zeros;
zeros = 0;
odds = 0;
evens = 0;
cout << "The number you enter are: ";
for (int counter = 1; counter <= N; counter ++)
{
getNum(number);
cout << number << " ";
checkNum(number, zeros, odds, evens);
}
printResults(zeros, odds, evens);
system ("pause");
return 0;
}
void getNum(int& num)
{
cin >> num;
}
void checkNum (int num, int& zeroCount, int& oddCount, int& evenCount)
{
switch ( num % 2)
{
case 0:
evenCount++;
if (num == 0)
zeroCount++;
break;
case 1:
case -1:
oddCount++;
}
}
void printResults(int zeroCount, int oddCount, int evenCount)
{
cout << "There are " << zeroCount << " zero digits, " << oddCount << " odd digits"
<< " and " << evenCount << " even digits " << endl;
}
i can't get the answer....