Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My program is done and compilable. I need to add a sentinal command to stop the

ID: 3551478 • Letter: M

Question

My program is done and compilable. I need to add a sentinal command to stop the loop. When the program is compiled, It'll ask the user to type in a palindrome. I want the user to type EXIT to end the loop. Can anyone help me?


#include <iostream>

#include <fstream>

#include <cstring>



using namespace std;


int main(void)

{

char word[81];

do

{

bool palindrome=true;


cout << "Please enter a word" << endl;

cin>>word;

int length = strlen(word);

for (int i=0; i<length; i++)

{

word[i] = toupper(word[i]);

}

int(length/2);

if (length>0)

{

for(int i=0;i<(length);i++)

{

if(word[i]!=word[length-1-i])

palindrome=false;

}

}


if(palindrome==true)

{

Explanation / Answer

#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

int main(void)

{

        char word[81];

        do

        {

                bool palindrome=true;


                cout << "Please enter a word" << endl;
                cin>>word;
                // Input EXIT to exit program
                if(!strcmp(word,"EXIT")){
                cout<<" Exiting " <<endl;
                break;
                }
                int length = strlen(word);

                for (int i=0; i<length; i++)

                {

                        word[i] = toupper(word[i]);

                }

                int(length/2);

                if (length>0)

                {

                        for(int i=0;i<(length);i++)

                        {

                                if(word[i]!=word[length-1-i])

                                palindrome=false;

                        }

                }


                if(palindrome==true)

                {
                       cout << "The word is a palindrome" << endl;
                }
                else
                {
                        cout << "The word is not a palindrome" << endl;
               
                }
                
        }
                while(1);
                return(0) ;
                               
}
                

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote