• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me on this palindrome program

 
avelin chen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





The output is supposed to be:

Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

While on the other hand, my output is:
Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: true<--SUPPOSED TO BE FALSE

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

I don't know how to change it without altering the other palindromes. Help will be greatly appreciated!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you call checkData() anywhere ?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps isAlmostPal() should call isPal() first to determine if it is a true palindrome. What can you do with this result to return the value you expect?

Also, you don't need all the if...else statements for your output. Instead you can print the output in a single line:
 
Adam Price
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by avelin chen:

Maybe I am not understanding what the criteria are?

You want anything that is a Palindrome to fail at being an almost palindrome, right? Run that check first - if it passes isPal, it should return false for isAlmostPal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic