title: Function call passing incorrect number (C++ 11)
body: <p>I'm currently working on a project that is meant to teach the usage of functions in C++. I've worked with python in the path and have a reasonable understanding of functions in code (or so I thought) but for some reason I'm getting some alarming errors when I pass values through to my current function.</p>
  
  <p>This is the entire code, my problem lies within the narc_num(153,3) call made in main. I added some cout statements into the narc_num function to see why I was getting wonky results and found that the num argument was getting passed as a completely different number. Why would this be?</p>
  
  <pre><code>#include&lt;iostream&gt; 
  #include&lt;cmath&gt; 
  using std::cin; 
  using std::cout; 
  using std::endl; 
  
  /* 
  Function: order_parameters 
  Purpose: If first is greater than second reassign the values so second is greater than first 
  Algorithm: 
  1.Pass arguments as references to first and second 
  2.if statement that runs if first is greater than second 
  3.within if statement switch values using a temporrary variable 
  4.if else doesnt run nothing happens 
  */ 
  void order_parameters(long &amp; first,long &amp; second)//passing long references of first and second 
  { 
   if(first &gt; second)//start if when the ref to first &gt; ref to second 
   { 
   long temp; // initialize temp 
   temp = second; //value temp is = to second 
   second = first; //second will now be first, temp is still = to first though as well 
   first = temp; //second is now set = to temp, which is first. dat swap 
   }//end if 
  } 
  
  /* 
  Function: narc_num 
  Purpose: check if a number is indeed a narcisstic number 
  Algorithm: 
  1.Pass num, the number to be checked, and power, the order the number will be checked against 
  2.use a while loop to iterate through digits of number 
      -mod10 takes the last digit, the digit is raised to the power passed as an argument 
      -the value found is added to the total 
      -the number is then divided by 10 to remove the last digit, reiterates again. 
  3.the total found by the while loop is checked against the number passed an as argument 
      -if the total is equal to the number it is narcisstic. 
  */ 
  bool narc_num(long num, long power)// will return a boolean value, passing num and power integers 
  { 
  //split all digits into seperate numbers, add together raised to power 
  long total = 0,digit,num_copy; 
  bool narc = false; //value to check if number is narcissitic or not 
  num = num_copy; 
  cout &lt;&lt; "number"&lt;&lt; num &lt;&lt; endl; 
  while(num &gt; 0) 
      {digit = num%10; 
       cout &lt;&lt;"digit" &lt;&lt; digit &lt;&lt; endl; 
       total += pow(digit,power); 
       cout &lt;&lt;"total" &lt;&lt; total &lt;&lt; endl; 
       num /= 10; //divides by 10 to go to the next digit down 
      } 
  if (total == num) 
      narc = true; 
  cout &lt;&lt; total &lt;&lt; endl; 
  return narc; 
  } 
  
  long check_range(long first,long last,long power) 
  { 
  bool check; 
  order_parameters(first,last); //make sure parameters are in correct order 
  for(first;first == last;first++);//iterate through all numbers from first to last 
    {check = narc_num(first,power); //check = True if narc number otherwise false 
     if (check == true) 
     {cout &lt;&lt; first &lt;&lt;" is a narcissistic number of order " &lt;&lt;power&lt;&lt; endl; 
     }; 
     cout &lt;&lt; "gothere"&lt;&lt; endl; 
     }; 
  cout &lt;&lt; "dick canoe"&lt;&lt; endl; 
  } 
  
  int main(){ 
  narc_num(153,3); 
  } 
  </code></pre>