I'm trying to reverse a string in pairs
Example: input - heaven
output - ne va eh
My code seems to be right until the last for loop...
That's where I need help
Here's my code:
#include <iostream>
#include <string>
using namespace std;
string revString(string user);
int main()
{
string user;
cout<<"Enter a random text"<<endl;
getline(cin,user);
unsigned int length=user.length();
while (length%2 == 1)
{
cout<<"enter the text with even amount of letters"<<endl;
getline(cin,user);
length = user.length();
}
string revstr = revString(user);
cout<<revstr;
return 0;
}
string revString(string user)
{
string rev;
for(int i =1; i<=(int)user.length();i+=2)
{
rev = user.length[i+1];
rev = user.length[i];
}
return rev;
}