Question #308767

Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Done", "done", or "d" for the line of text. 

Ex: If the input is:

Hello there
Hey
done

then the output is:

ereht olleH
yeH

Expert's answer

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main()
{
    string s;
    getline(cin,s);
    while((s!="Done")&&(s!="done")&&(s!="d"))
    {
        reverse(s.begin(),s.end());
        cout<<s<<endl;
        getline(cin,s);
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS