Where is the wrong??? Why does not this program work??

#include <iostream>
using namespace std;

// Function prototypes.
int resverseDigit (int);

int main()
{
  int num;

  // Test function resverseDigit(num).
  cout << "Enter the number: "
       << endl;
  cin >>num;

  return 0;

} // End of main

// Function Definitions

   int resverseDigit (int num)
      // Returns the number with it digit reverse
  {
	   int digit; // local verable

	  while (num != 0)
	  {
      digit= num%=10;
	  num/=10;
	  }

	return digit;
  }

thanx,
buy

1. You have a function prototype
2. You have a main function that only prompts for an integer, you never call on the function so it's never executed
3. You have a function that never gets run.

You need to call the function, for example:

num = reverseDigit(98);

Here num gets assigned the return value. Remember that you need to pass a digit to the function as well. I'm passing the digit 98, but you could always pass a variable if you want.

1st tooo much common sense comment :

second ;

while (num != 0)
{
digit= num%=10;  // you are setting digit to the last number of 10 each time this loop runs. So you end up with a 1 digit number
num/=10;
}

To reverse the number first find out its degree, i.e 1 has a degree
of 0, 10 has a degree of 1, 100 has 2, 1000 has 3 ....

The use the mod operator to extract the last number of
the value passed from the parameter, and multiply it with
the total degree. Then divide degree by 10, and again
add the num%10 * degree .. and repeat, until !deg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.