string rev;
    for(int i =1; i<=(int)user.length();i+=2)
    {
        rev = user.length[i+1];
        rev = user.length[i];
    }

this is a part of my code where "user" is the user inputted text.

I'm trying to get the output to do this.
input - square
output - er au qs

I've been stuck on this for a long time; i can't seem to figure it out.

Please help.

Recommended Answers

-You are setting the value of rev to one character at a time. What you need to is use string append() or +-operator to add characters to string.

- String indexing start from 0, like most indexing in C++

- If you want to loop user string from …

Jump to Post

All 2 Replies

-You are setting the value of rev to one character at a time. What you need to is use string append() or +-operator to add characters to string.

- String indexing start from 0, like most indexing in C++

- If you want to loop user string from 0..length-1, you must add the characters in the beginning of the string. You can also switch your looping to start from length-1 and end at the beginning.

- Don't forget to add an extra whitespace with every two new characters

Hope that helps!

thanks

Be a part of the DaniWeb community

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