# find no of even factor, express as %

This is a discussion on find no of even factor, express as % within the C++ Programming forums, part of the General Programming Boards category; question: enter a number, find number of even factor and expressed as percentage i have type in the code and ...

1. ## find no of even factor, express as %

question: enter a number, find number of even factor and expressed as percentage

i have type in the code and compiled it sucessfully. But the reuslt wasn't expected (always come as 0). Can someone please help to solve the problem. I am using a blood shed dev cpp ver 4.01.
Here is my code

Code:
```int c(int day)
//find the even factor of day and expressed as percentage
//pre: day>0
//post: return percentage
{
int eFactor;//even factor
int tFactor;//total factor
int i;//control variable
int percent;//express as percentage

//initialization
eFactor = 0;
tFactor = 0;

for (i=1; i<=num; i++)
{
if (num%i==0)
{
tFactor++;
if (i%2==0)
eFactor++;
}//end if
}//end loop

percent = (eFactor / tFactor)* 100;
return percent;
}//end c```

2. Also the if-clause
Code:
`if (num%i==0)`
is not neccesary.

Your function should return a double or a float and not an integer number.

3. As a minor point, the number of even factors will be equal to the number of times you can divide by 2.
Code:
```int num_even(int n) {
int num=0;
while(n>1 && n%2==0) {++num;n/=2;}
return num;
}

int num_odd(int n) {
n >>= num_even(n);
int num=0;
const int lim = ceil(sqrt(n));
for(int d=3;n>1 && d<=lim;d+=2) {
while(n%d==0) {
++num;
n/=d;
}
}
return num;
}```
also consider what happens with your loop on 12 (3*2*2) this should be 66% but yours(fixing round off) will return 50%