check elements on string to see if palindrome

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; int main () { string word; int wordsize; // use getline, not cin >> because using strings cout << "Please enter a word." << endl; getline (cin, word); wordsize = word.length(); cout << "The length of the word is " << wordsize << "." << endl; for (int i=0; i < wordsize/2 ; i++) { // if statement for word if equal, break loop and return YES if (word[i]==word[wordsize-i-1]) { cout << "Checking element " << i << " with element " << wordsize - i -1 << "." << endl; } // if statement for word not equal, returns NO if (word[i]!=word[wordsize-i-1]) { cout << "Checking element " << i << " with element " << wordsize - i -1 << "." << endl; cout << "NO: it is not a palindrome." << endl; return 0; } } cout << "YES: it is a palindrome." << endl; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines