I need to write a program to create palindrome words by using the string entered by users.
The program should have 2 strings:
the first string is used to store input text from the user
and the second string is to store the same input text from the user in reverse direction.
Display the palindrome words at the end of program.

Sample of input: ABCD

Sample of output: ABCDDCBA

this is my code, but it is not working as I want :

#include <iostream>

using namespace std;

int main()

{
    char i;
    string str1[i], str2[i];
    cout << "please Enter the text  " << ": "<<"\n";
    cin >> str1[i];


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

    cout << str1[i] << endl;


cout << "\n";

for (int i = 9; i >= 0; i--)

        cout << str2[i] << endl;

return 0;
}

You haven't written the code to reverse the str1 string. Also, your string variables are being declared as an array, and you are putting the input string in a likely bogus position of that array. To declare them properly, do this: string str1, str2; Next, in your loops you look for a maximum size of 10. This is not correct. Look for the terminating null character instead as the guard. IE: for (i = 0; str1[i] != 0; i++). This will give you the size of the actual string (as i) after all is said and done. You also need to declare i outside of the loop as a sizeof_t and not a char so you can use it in the reversal code for any length of string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.