Skip to main content
added 48 characters in body
Source Link
gone
  • 161
  • 5

Remove the "type exit to exit" thing. What if someone wants to reverse "exit" → "tixe"? Simply use the standard for ending programs, ^C (Control-C). You don't even need to implement anything. If someone wants to exit they simply Control-C.

Final:

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

int main(int argc, char** argv) 
{

  while(true)
  {
    string input;
    cout << "Enter the text you want to reverse: ";
    getline(cin, input);

    reverse(input.begin(), input.end());
    cout << "The reversed version of your text is: " << input << endl << endl;
  }      
  return 0;
}

Remove the "type exit to exit" thing. What if someone wants to reverse "exit" → "tixe"? Simply use the standard for ending programs, ^C (Control-C). You don't even need to implement anything.

Final:

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

int main(int argc, char** argv) 
{

  while(true)
  {
    string input;
    cout << "Enter the text you want to reverse: ";
    getline(cin, input);

    reverse(input.begin(), input.end());
    cout << "The reversed version of your text is: " << input << endl << endl;
  }      
  return 0;
}

Remove the "type exit to exit" thing. What if someone wants to reverse "exit" → "tixe"? Simply use the standard for ending programs, ^C (Control-C). You don't even need to implement anything. If someone wants to exit they simply Control-C.

Final:

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

int main(int argc, char** argv) 
{

  while(true)
  {
    string input;
    cout << "Enter the text you want to reverse: ";
    getline(cin, input);

    reverse(input.begin(), input.end());
    cout << "The reversed version of your text is: " << input << endl << endl;
  }      
  return 0;
}
Source Link
gone
  • 161
  • 5

Remove the "type exit to exit" thing. What if someone wants to reverse "exit" → "tixe"? Simply use the standard for ending programs, ^C (Control-C). You don't even need to implement anything.

Final:

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

int main(int argc, char** argv) 
{

  while(true)
  {
    string input;
    cout << "Enter the text you want to reverse: ";
    getline(cin, input);

    reverse(input.begin(), input.end());
    cout << "The reversed version of your text is: " << input << endl << endl;
  }      
  return 0;
}