Hi, im having some problem while doing my assignment, i cant make my recursive function to loop as to get each digit from the number generated randomly.
int random (int num) {
srand (time (NULL)); num = rand(); cout << num << endl; if (num != 0) return num % 10; num = num / 10; }
Wat im trying to do here is to get each digit from the number, for example, number show is 3859, i should get the result of 9 5 8 3. But from my coding i'll only get the last digit, that's 9.
Thanks
One, you're going to get really lousy random numbers since you keep seeding the random number generator. Just seed it once at the top of the program. Two, there's no reason to pass this function anything. num is immediately overwritten at the top of the function before you do anything with it, so its value is lost. Three, this isn't a recursive function. Four, please use code tags:
[code]
// paste code here
[/code]