help me quick plzzz

i have to write a program that says whether the number i enter is Naracissistic or not.
i wrote the codes and everything but every time i write 153 or 24678051 it says its not a Naracissistic number :( plz tell me whats wrong with the codes i wrote :(

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
  # include <iostream>
# include <cmath>

using namespace std;

bool isNarcissistic (int num1);

int main()
{
    int num1;


    cout << "Enter a positive number";
    cin >> num1;

    if (isNarcissistic(num1))
        cout << num1 << "is Narcissistic";
    else
        cout << num1 << "is no Narcissistic";

    return 0;
}
bool isNarcissistic(int num1)
{
   int x1;
   int x2;
   int digit;
   int sum = 0;
   int i = 0;

   x1 = num1;

   while (x1 != 0)
   {
       digit = x1 % 10;
       x1 = x1 /10;
       i++;
   }
   x2 = num1;

   while (x2 != 0)
   {
       digit = x2 % 10;
       x2 = x2/10;
       sum = sum + pow(digit,i);
   }
   if (sum == num1)

       return true;
   else

    return false;
}
Works for me, after i replaced line 45 with sum = sum + int(pow(1.0*digit,i));
http://codepad.org/jQXXH3QB
oh thnks!

i just wanted to ask why did u multiply the digit by 1.0 ?
I just wanted to make it double. pow function is defined as double pow(double base, double exponent); and codepad site does not like warnings
oh ok, thnk u :)
Topic archived. No new replies allowed.