CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

not all code paths return a value topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2010, 02:25 PM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jc1forall is on a distinguished road
| More
not all code paths return a value

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:
Code:
 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.

Last edited by shabbir; 09-03-2010 at 02:33 PM. Reason: Code Blocks
Reply With Quote
  #2  
Old 09-04-2010, 01:34 AM
coderzone's Avatar
Senior Member
 
Join Date: May 2007
Posts: 273
Thanks: 16
Thanked 12 Times in 12 Posts
coderzone is on a distinguished road
| More
Re: not all code paths return a value

Your main function is not returning any value and so you are getting that error.
Code:
         if (palindromeTest == true)
         {
            Console.WriteLine("Yes the word is a palindrome.");
         }
         else
            Console.WriteLine("No, that word is not a palindrome");
Just make sure you have a return statement after the if else or inside each of if else.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
return makes integer from pointer without a cast Tlhoks C Programming 0 08-28-2010 03:11 AM
return of make utiliy from system function vishnu.prasad C Programming 0 08-28-2010 03:11 AM
I want to return the date a week ago from today Rocket452 C# Programming 3 01-23-2009 05:16 AM
Functions that return two values psppb C++ Programming 2 02-12-2008 10:11 PM
Beginners Question on 'return' MartijnMulder C# Programming 1 12-08-2006 02:33 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:13 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board