Program Challenge:
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.
My question:
So far I have been able to output the reverse of the first line and end the code but how do I check and reverse the next line of input?
How it should look like:
Input:
Hello there
Hey
done
#include <iostream>
usingnamespace std;
int main() {
string inputText;
while (
cout << "Enter a line of text ... bla, bla to quit: "
&& getline(cin, inputText)
&& (inputText != "Done" && inputText != "done" && inputText != "d")
)
{
for ( int i = inputText.length() - 1; i >= 0; i--)
{
cout << inputText[i];
}
cout << endl;
}
return 0;
}
Enter a line of text ... bla, bla to quit: bla bla bla
alb alb alb
Enter a line of text ... bla, bla to quit: Don't quit yet
tey tiuq t'noD
Enter a line of text ... bla, bla to quit: Done
Program ended with exit code: 0