# Thread: help with a number counting function

1. ## help with a number counting function

in the program, there is a section where you generate a series of numbers that is seeded from a user's input. the user also determines how many numbers should be generated. this part is fine, however, it also has to count the number of positives, negatives, zeros, odds, and evens and print them to screen. plz helllllp

Code:
```void genRandom(int seed, int lb, int ub, int numToGen,
int* pEven, int* pOdd, int* pNeg, int* pPos, int* pZero)
{
int i;
int randNum;

srand(seed);
printf("\nNumbers generated:");
printf("\n");
for (i = 0 ; i < numToGen; i++)
{
randNum = rand() % (ub - lb + 1) + lb;
printf("%4d", randNum);
}
addToCounts(randNum, pEven, pOdd, pNeg, pPos, pZero);

printf("\n\n");
return;
}

void addToCounts(int randNum, int* pEven, int* pOdd,
int* pNeg, int* pPos, int* pZero)
{
int i;

for (i = 0; randNum > 0; i++)
pPos++;
}```

the addToCounts function is the one where i have no idea what to do. i only have pos in there to try to figure it out but i intend to include all the rest. thank you for your time

2. The variables go to addToCounts will be pointers. They should be set to zero before the numbers are generated.

If statements will sort out the counting of pos, neg, etc.

Code:
```if(randNum > 0)
*pos++;
else if(randNum < 0)
*neg++;

if(randNum % 2 == 0)```
well, you should figure out the rest.

Get some indentation going on that program! It will help you find your logic and syntax errors, easier.

3. If you take a look at the operator precedence http://www.decom.ufop.br/prof/romild...c-op-prec.html

you'll see that
*pos++;

is equivalent to
*(pos++);

I do not see what it can be good for

4. Obviously Adak just meant ++*pos and ++*neg, or (*pos)++ and (*neg)++. As for what the *pos++ syntax can be good for, I suppose the canonical strcpy() implementation is one example:
Code:
`while (*dest++ = *src++);`

Popular pages Recent additions