Answer to Question #308767 in C++ for Program Training

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
1
Expert's answer
2022-03-10T02:09:32-0500
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog