Thread: Palindrome - Press enter to continue...

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    61

    Palindrome - Press enter to continue...

    Hi,

    The part of the Palindrome is working but i want to my program to print "Press ENTER to continue" in the end of each cycle.

    It is working but i donīt think that is the best way.

    Code:
     // Problem here - I Want to press enter to continue what is the best way ?
            cin.get();
            cout << "Press enter to continue";
            cin.get();

    FULL CODE
    Code:
    using namespace std;
    
    
    string invertePalavra(string s) {
        return string(s.rbegin(), s.rend());
    }
    
    
    void ficha1_ex8() {
        string word;
        cout << "Write  \"end\" to exit\n";
        while (true) {
            cout << "Write a word: \n> ";
            cin >> word;
            if (word == "end")
                break;
            string inv = invertePalavra(word);
            cout << "word -> " << word << endl;
            cout << "Reverse word -> " << inv << endl;
    
    
            if (word == inv) {
                cout << "palindrome \n";
            } else {
                cout << "Not a palindrome\n";
            }
    
    
            // Problem here - I Want to press enter to continue what is the best way ?
            cin.get();
            cout << "Press enter to continue";
            cin.get();
            
        }
    }
    
    
    int main(int argc, char** argv) {
        ficha1_ex8();
    
    
        return 0;
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,609
    It depends on what you mean by best. The way that you've presented is standard and portable.

    Have you thought about not doing it? That would be my real suggestion. There should be nothing wrong with the program ending, closing the window, after you type "end" because you should have seen the words reversed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "press any key to continue" without the enter key
    By chickenandfries in forum C Programming
    Replies: 1
    Last Post: 03-29-2008, 09:56 PM
  2. Press enter to continue... beginner code
    By rox in forum C Programming
    Replies: 17
    Last Post: 12-02-2003, 05:32 PM
  3. press enter to continue
    By stimpyzu in forum C++ Programming
    Replies: 6
    Last Post: 10-30-2002, 08:01 AM
  4. press enter to continue
    By Klinerr1 in forum C++ Programming
    Replies: 12
    Last Post: 06-27-2002, 11:43 AM
  5. Press enter to continue
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-29-2002, 11:18 PM

Tags for this Thread