What am i doing wrong here? question on palendrone program

I know it probably looks pretty bad but im very new to c++ here is the prompt:
Given a number, reverse its digits and add the resulting number to the original number. If the result isn't a palindrome, repeat the process. I thought my logic was pretty good but for some reason my output isnt coming out right. please help..thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <locale>
#include <sstream>
#include <string> 
#include <cstdlib>
#include <list>
#include <algorithm>

using namespace std;
void palin(std::string a);
bool check_the_result(string a);

int main()
{
     string number;
   cout<<"enter the number:"<<endl;
   cin>>number;
   int numm = 0;
   int length = number.length();
   int Num = length - 1;
  palin(number);
  
   
   
    
    
}




 void palin(std::string a)
{ 
    
    
    int length = a.length();
     int b = length-1;
     
     int origNUM = atoi(a.c_str());
     
     
     
     for(int begin = 0; begin<length/2;begin++,b--)
        { 
        
            std::swap(a[begin],a[b]);
        }
        
         int newNum = atoi(a.c_str());
         int newNUM = newNum + origNUM;//number to be converted to string
         std::string Result;          // string which will contain the result
         ostringstream convert;   // stream used for the conversion
         convert <<newNUM;   // insert the textual representation of 'Number' in the charactes in the stream
         Result = convert.str(); // set 'Result' to the contents of the stream
  //now we have the added number from the two previous numbers stored in "RESULT"
 cout<<Result<<endl;
 check_the_result(Result);
    if(check_the_result==false)
    {
        palin(Result);
       
    }
    else
    {
       cout<<Result<<endl; 
    }
}
    
    
    
    
      
bool check_the_result(string a)
{
    int length = a.length();
    int counter = 0;
    int b = length - 1;
   while(counter<length/2)
   {
       if(a[counter]!=a[b])
        {
           
           return false;
           break;
        }
        else 
        {
          counter++; b--;
            return true;
        }
       
    }
    
}



  
 
My first suggestion is insure your compiler is generating the maximum number of warnings and never ignore these warnings.

Here are the warnings my compiler reports about your code:

main.cpp||In function ‘int main()’:|
main.cpp|22|warning: unused variable ‘numm’ [-Wunused-variable]|
main.cpp|24|warning: unused variable ‘Num’ [-Wunused-variable]|
main.cpp||In function ‘void palin(std::string)’:|
main.cpp|62|warning: the address of ‘bool check_the_result(std::string)’ will never be NULL [-Waddress]|
main.cpp||In function ‘bool check_the_result(std::string)’:|
main.cpp|98|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 0 errors, 4 warnings (0 minutes, 1 seconds) ===|


thanks for responding..
im using an online compiler so thats may be why i wasnt getting those warnings..thanks for showing them to me. Im working on them now
Topic archived. No new replies allowed.