Another recursive problem. I'm trying to write a function that reverses an int value recursively. I think I've got the algorithm right, but I can't get the base case right. So my program ends up printing 5 infinitely... Here's the code:
#include <iostream>
#include <cmath>
using namespace std;
void reverseDisplay(int value){
while (value != 0){
if (value < 0){
cout << "-" << abs(value % 10);
reverseDisplay(value / -10); }
else{
cout << value % 10;
reverseDisplay(value / 10); } } }
int main(){
reverseDisplay(54321);
reverseDisplay(-54321);
return 0; }