Logic control

2. Write a program that prompts the user to input an integer number (can be positive or negative) and then output the number with the digits reversed. For example if the input is 12345, the output should be 54321. Your program must also output 800 as 008 and 130 as 031 and -123 as -321. Your program should continue to ask the user for input until the response is negative.

can anyone help.. i am new in programming.
closed account (o3hC5Di1)
Hi there,

The assignment states "Write a program that prompts the user to input an integer number" - It doesn't say you need to store it as an integer.

The easiest way to go about this would be to put the input into a C-string (char - array) and subsequently reverse that using a for loop, i.e, in pseudocode:


char userinput[50], reverse[50]
ask for input >> userinput

for every character in userinput
    if the first character is a minus then keep that in front
    else put the current character at its new spot in reverse[50]


A function you might want to look into is the strlen() function in <cstring>.

Hope that gets you started.

All the best,
NwN
thanks mate!
Topic archived. No new replies allowed.