Skip to main content
Code Review

Return to Question

Post Closed as "Not suitable for this site" by Toby Speight, Sᴀᴍ Onᴇᴌᴀ
added 84 characters in body
Source Link

#include <iostream>
#include <string>

using namespace std;
string reversal(string a) {
 int i = a.length();
 string reversed_string{}; 
 for (; i >= 0; --i) 
 reversed_string += a[i];
 
 
 
 return reversed_string;
}
bool palindrome(string a) {
 
 if (a == reversal(a)) {
 
 cout << "this is a palindrome " << endl;
 return true;
 }
 else if(a != reversal(a))
 {
 cout << "this is not a palindrome " << endl;
 return false;
 }
}
int main(){
}

This is my program for the palindrome program, finding the reverse of a string was the simpleless tedious part however the palindrome function does not work ,and i don't understand why.


string reversal(string a) {
 int i = a.length();
 string reversed_string{}; 
 for (; i >= 0; --i) 
 reversed_string += a[i];
 
 
 
 return reversed_string;
}
bool palindrome(string a) {
 
 if (a == reversal(a)) {
 
 cout << "this is a palindrome " << endl;
 return true;
 }
 else if(a != reversal(a))
 {
 cout << "this is not a palindrome " << endl;
 return false;
 }
}

This is my program for the palindrome program, finding the reverse of a string was the simple part however the palindrome function does not work ,and i don't understand why


#include <iostream>
#include <string>

using namespace std;
string reversal(string a) {
 int i = a.length();
 string reversed_string{}; 
 for (; i >= 0; --i) 
 reversed_string += a[i];
 
 
 
 return reversed_string;
}
bool palindrome(string a) {
 
 if (a == reversal(a)) {
 
 cout << "this is a palindrome " << endl;
 return true;
 }
 else if(a != reversal(a))
 {
 cout << "this is not a palindrome " << endl;
 return false;
 }
}
int main(){
}

This is my program for the palindrome program, finding the reverse of a string was the less tedious part however the palindrome function does not work ,and i don't understand why.

Source Link

Palindrome string program


string reversal(string a) {
 int i = a.length();
 string reversed_string{}; 
 for (; i >= 0; --i) 
 reversed_string += a[i];
 
 
 
 return reversed_string;
}
bool palindrome(string a) {
 
 if (a == reversal(a)) {
 
 cout << "this is a palindrome " << endl;
 return true;
 }
 else if(a != reversal(a))
 {
 cout << "this is not a palindrome " << endl;
 return false;
 }
}

This is my program for the palindrome program, finding the reverse of a string was the simple part however the palindrome function does not work ,and i don't understand why

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /