# Help!!!!!

• 10-11-2002
tetraflare
Help!!!!!
hi im new at programming, and i need to write a program that takes an integer value and returns the number with its digits revered. sooo basically a pallindrome? ex. 12345 would be 54321

but heres the catch i dont know how many integers the user will enter. so how would i go about writing this code?

any help is greatly appreciated thanks.
• 10-11-2002
Prelude
Write a function which repeatedly calculates the least signifigant digit and adds it to a return value, then divide the number by 10. When the value is zero, return the reversed value. The calculation would be something like this:

ret = ( val % 10 ) + ret * 10;

-Prelude
• 10-11-2002
tetraflare
wow ok well when i said iw as new at programming i meant NEW :) strings we havent coverd thats like chaper 16 lol we are on 3 :) if anyone who can help me please post your aim handle if possible or contact me mine is gigaflare999 thanks for the replys btw i appreciate it, i just need like serious help lol :)
• 10-11-2002
Prelude
>if anyone who can help me please post your aim handle
I'm hurt ;), I pretty much gave you the solution without using strings. Just throw it in a loop and you're done:
Code:

```while ( val != 0 ) {   ret = ( val % 10 ) + ret * 10;   val /= 10; }```
Now ret is the reversed val.

-Prelude
• 10-11-2002
tetraflare
sheesh sorry :) i was lscared when i saw string [256] i ran in other direction! :( thanks for helpnig i get whiles easy! i appreciate it but will that work no matter how many ints they put in?
• 10-11-2002
Prelude
>i appreciate it but will that work no matter how many ints they put in?
It will if you place it in a loop. :rolleyes:
Code:

```#include <iostream> int reverse ( int val ) {   int ret = 0;   while ( val != 0 ) {     ret = ( val % 10 ) + ret * 10;     val /= 10;   }   return ret; } int main() {   int num = 0;   std::cout<<"Enter a number (CTRL+Z to quit): ";   while ( std::cin>>num ) {     std::cout<<"Your number reversed was: "<<reverse ( num ) <<std::endl;     std::cout<<"Enter a number (CTRL+Z to quit): ";   }   return 0; }```
-Prelude
• 10-11-2002
tetraflare
omg thankyou so much you dont know how much you helped me. really. if you could reccomend any learning sites that are like uber simple please do, my computer teacher sucks ass so bad he doesnt teach. :(