First of all, forgive my lack of knowledge, I am fairly new to programming but I have a high level of interest in the subject. We were working on a bit of code in class yesterday and we even stumped our teacher, who then took most of the class trying variations of this code. We were attempting to write a program that would determine if input was a palindrome. The only way I could think to do it was as follows, but I kept getting the error message in the title:
class Program
{
public static bool isPalindrome(int first, string word, int last)
{
if (word[first] != word[last])
{
return false;
}
else if (first < last)
{
isPalindrome(first + 1, word, last - 1);
}
else
return true;
}
static void Main(string[] args)
{
string word;
Console.WriteLine("Enter a word to test: ");
word = Console.ReadLine();
int last = word.Length - 1;
bool palindromeTest = isPalindrome(0, word, last);
if (palindromeTest == true)
{
Console.WriteLine("Yes the word is a palindrome.");
}
else
Console.WriteLine("No, that word is not a palindrome");
}
}
I guess my question is- in what scenario would a call of the method not return a value? Thanks for any help.