Hi guys, I'm trying to use a recursive function to drop the last digit and enter a space, it would be like this:
Enter a number: 123
Output:
3
2
1
I was trying to do it but it gives me errors... and by the way, why can't I assign a double to my numb variable and then write this: get_whole_decimal = (numb / 10);
if I put it like that it gives me errors, it's like if it cannot accept doubles.
It would be helpful if you could tell us what errors you're getting, as that helps us narrow down what part of your code is broken. That being said, you did well to include your source code. I can see a few problems right now. First, you prototype get_last_numb() as taking a double, but then you define it as taking an int. This is likely the source of some of your errors. Second, If I'm reading what you're trying to do correctly, line 36 needs to be numb = drop_last;. Remember that the object being stored TO is always the object on the left. As it is, you're storing the result from line 35 into drop_last, then immediately overwriting it in line 36. Third, because of the second problem, numb never gets changed. This will cause your recursion to never hit the base case, and if the program were compiled and run, it would crash with a stack overflow or segmentation fault; probably the former.