title: converting decimal to string and string to decimal using char type
body: <p>My code is not giving me exact values. Can somebody tell me what's wrong? A few values give me the correct answer, but try <code>78</code>, <code>79</code>, <code>80</code> etc and you will know.</p>
  <p>If you could somehow correct it, that would be great.</p>
  <pre><code>//hi // Example program
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int stringToDecimal(string X)
  {
      int digit = 0;
      //I believe there is some fault here.
  
      for (int i = 0;i &lt; (X.length() -1); i++)
      {
          char c = X[i] + 48;     
          digit = (c + (10 ^ i) )+ digit;
      }
      return digit;
  }
  
  int countDigit(int n)
  {
      int count = 0;
      while (n != 0) {
          n = n / 10;
          ++count;
      }
      return count;
  }
  
  //I believe there is some fault here too
  string DecimalToString(int x)
  {
      string a= &quot;&quot;;
      for (int i =0 ; i &lt; countDigit(x); i++)
      {
          char digit = (x / (10 ^  i)) % 10;
          char c = digit + 48;
          a = a +c;
      }
      cout &lt;&lt; endl; 
      return a;
  }
  
  int main()
  {
      cout &lt;&lt; &quot;enter an integer&quot; &lt;&lt; endl;
      int a;
      cin &gt;&gt; a;
      cout &lt;&lt; DecimalToString(a) &lt;&lt; endl;
      cout &lt;&lt; stringToDecimal(DecimalToString(a));
      system(&quot;pause&quot;);
      return 0;
  }
  </code></pre>