hi i had a question how to reverse numbers, and someone graciously furnished me a script after alot of explination, but one thng i dont get is how this little snippit of cod can evaluate ALL integers with one loop! look.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int reverse ( int val )
{
int ret = 0;
while ( val != 0 ) {
ret = ( val % 10 ) + ret * 10;
val /= 10;
}
return ret;
}
int main()
{
int num = 0;
cout<<"Enter a number (CTRL+Z to quit): ";
while (cin>>num ) {
cout<<"Your number reversed was: "<<reverse ( num ) <<endl;
cout<<"Enter a number (CTRL+Z to quit): ";
}
return 0;
}
thanks