0

What is wrong with this code? Always the output is "Yes"

//Created by Homayoon Azizi //Declares if an array is palindrome or not #include <iostream> using namespace std; int main() { char A[]="abcdefg";//length=7 int z,c=0,d=0; for(int i=0;A[i]!='\0';i++)//__i=0~>6 c++;//_____________c=1~>7 z=c;//_____________z=7 c-=1;//____________c=6 for(int i=0;A[i]!='\0';i++){//_i=0~>6 if(A[i]=A[c])//___i=0~>6 c=6~>0 d++;//________d=1~>7 c-=1;}//_______c=5~>0 if(d==z) cout<<"Yes"; else cout<<"No"; return 0" }

22nd Dec 2017, 1:09 PM
Homay t
Homay t - avatar
2 Respuestas
+ 3
if you want to check if d and z have the same values, you should use '=='. Otherwise you will overwrite d with z value and see Yes in output anyway
22nd Dec 2017, 1:26 PM
Petr Leliaev
Petr Leliaev - avatar
0
@Petr Leliaev i always write '=' instead of '=='. Anyway i run the code and again same problem,still the output is "Yes"!!
2nd Jan 2018, 6:09 PM
Homay t
Homay t - avatar