help with this function please

Im tryint to write a program that lists each individual digit of an integer and then take the sum of those digits. The program runs but doesnt produce anything. ANy help would be much appreciated.

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
#include <iostream>
#include <cmath>
using namespace std;

int dig (int x);

int main () {
        int x;
        cout << "Enter an integer\n";
        cin >> x;
        if (x<=0) return 0;
        int dig (x);
        return 0;
}
int dig ( int x ){
        int tempnum, sum=0, divisor, digit, count=0;
        tempnum = x;
        while ( tempnum!=0){
                tempnum=tempnum/10;
                count++;}
        tempnum = x;
        do { divisor = static_cast<int>(pow(10.0, --count));
             digit = tempnum/divisor;
             tempnum= tempnum % divisor;
             cout << " " << digit;
             sum = sum + digit;}
        while (count!=0);
             cout << "\n Sum of the digits is = " << sum << endl;
}

                                                              30,1-8        Bot
Remove the return type when you actually call the function.

int dig (x);
Topic archived. No new replies allowed.