Okay, folks, I've got my OOP back on track.
Well I'm making a simple number guessing program into OOP, to make my head ache. And well, I decided to use rand(), (well actually rand() % 100 as suggested by an article) and if() to tame it so it can fit between 1 and 100. Here is the code:
Yes, I know. Everyone hates recursive functions. And in a sense this could go on for days. But the program loads and then crashes. Because of this (I just added this bit, and now it crashes.).Code:void CNumber::getRand() { int randNum; srand(time(NULL)); randNum = rand() % 100; if ((randNum < 1) || (randNum > 100)) { int equalRand(randNum); } else { getRand(); } }
There must be a better way of doing this. What is it?
Thanks.