I'm writting a program that generates a list of random numbers based on predefined parameters and counts the number of positives, negatives, zeros, evens and odds. I had it working fine when it was all in main() but when I broke it up into separate functions it would not display the number of positives etc. correctly.
Here is the code for the part that I believe is giving me trouble:
That string of if/else statements at the end should be counting the number of evens, odds etc. but all I get for the values is 0 when I compile and run the program. I've looked through the FAQs and my textbook but nothing has clued me in to why it isn't working the way I want.Code:int looper(int seed, int upper, int lower, int num, int* pos, int* neg, int* zero, int* even, int* odd) { int rnum, teh; //rnum is random number, teh counts the loops srand(seed); for (teh=0; teh<num; teh++) //loop controles # of randoms { rnum= (rand()%(upper-lower))+lower; if(teh==10 || teh==20 || teh==30 || teh==40 || teh==50) //new line every 10 loops { printf("\n"); } printf(" %d", rnum); //print the random if(rnum>0) //counts positives, neg, zero, even & odds { pos++; } else if(rnum<0) { neg++; } else { zero++; } if((rnum%2)==0) { even++; } else { odd++; } } printf("\n"); }
Thanks in advance for any help.



LinkBack URL
About LinkBacks



