title: a simple program that counts and sums digits. How can I make it work?
body: <p>So I've to write a simple program(that loops) where you can enter an int and it spews out the number count and the sum of the numbers. Since I am such a tard when it comes to programming, I just scavenged the code online and tried to piece it together. I guess the sum block screws with n, but I am not really sure. Anyway, I would really appreciate it if somebody could point out mistakes and show me how can I make it work.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      while(1)
      {
          int i,p,n,sum=0;  //sum block
          cout&lt;&lt;"enter an int: ";
          cin&gt;&gt;n;
  
          {
              while(n!=0)
              {
                  p=n % 10;
                  sum+=p;
                  n=n/10;
              }
              cout&lt;&lt;"int digit sum: "&lt;&lt;sum &lt;&lt;endl;
          }
          {
              int count = 0;
              while(n)
              {
                  n /= 10;
                  ++count;
              }
              cout &lt;&lt;"number of digits: " &lt;&lt; count &lt;&lt; '\n';
          }
      }
  }
  </code></pre>