15,904,926 members
1.00/5 (1 vote)
See more:
Write a C++ program that prompts a user to enter a four-digit integer and prints the number in reverse. HINT: Print one digit at a time, starting from the right of the number.

Sample run of program:

Enter a four-digit number: 3412
Your number in reverse is 2143

I couldn't figure out the last part, which was flipping the last number.

What I have tried:

i got most of it done i just can figure out how to flip the last number. how would i do this.

could you actually walk me through it tho im tryna learn.
Posted
Updated 16-Feb-23 22:16pm

## Solution 1

Start by thinking "how would I do that manually?"
Write the number on a blackboard then take the lowest digit out and write that down, then rub it out.
If there are any digits left you do it again until there aren't.

So you need three things:
1) A loop that stops when you run out of digits. Hint: think about the `do`...`while` loop
2) A way to extract the least significant digit. Hint: what does the modulus operator do?
3) A way to remove the least significant digit. Hint: how does integer division differ from floating point division?

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

CPallini 17-Feb-23 2:10am
5.
Andre Oosthuizen 17-Feb-23 4:42am
4+x=5

## Solution 2

Try with starting some Learn C++ tutorial or some video tutorial.

I strongly recommend that you take the time to read my tips to learn from my experiences in that industry.

some tips: use functions and classes with understandable names and install some IDE like Visual Studio.