I can not get my C++ program to work right. It is supposed
to tell if a word is a palindrome or not, but it only tells
thet the word is not a palindrome. And I can't fix it.



I can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not..

Answer / sam

#include <iostream>
using namespace std;

int pali (char word[30]);
int main () {

char word[30];
char ans[5];
int answer;

cout << "Please enter a word (in all lowercase letters)"
<< endl;
cin.getline(word,30);

answer = pali(word);
if (answer == 1){
strcpy(ans,"a");
}
else{
strcpy(ans,"not a");
}
cout << " The word you entered was " << ans << "
palidrome" << endl;

}

int pali(char word[30]) {

char flip[30];
int length;
length = strlen(word);

for (int w = length-1, f = 0 ; w > -1; w--, f++) {
flip[f] = word[w];
}
strcmp(word,flip);
if (word == flip) {
return 1;
}
else {
return 0;
}
}

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C C++ Errors Interview Questions

how tally is useful?

2 Answers  


Assume that the int variables i and j have been declared, and that n has been declared and initialized. Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consistings of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be * ** *** You should not output any space characters. Hint: Use a for loop nested inside another for loop.

2 Answers   HCL,


class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }

1 Answers  


main() { char c; for(c='A';c<='Z';c++) getch(); }

9 Answers  


Why are memory errors hard to debug?

1 Answers  






What is probability to guarantee that the task a programmer is going to create will be created and be able to run on a particular system (RTOS/GPOS).

0 Answers  


what is meant for variable not found?

3 Answers  


what is syntax error?

3 Answers  


write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;

2 Answers  


I can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not, but it only tells thet the word is not a palindrome. And I can't fix it.

1 Answers  


who was the present cheif governor of reserve bank of india

6 Answers   State Bank Of India SBI,


Categories