Not All Control Paths Return a Value

in this assignment we're supposed to use recursion as a technique for determining whether a word qualifies as a palindrome. although i'm still struggling to become comfortable with it as a problem solving mechanism, this code seems like it should otherwise work. however, the visual c++ 2010 compiler gives me the "not all control paths return a variable" error:

1>c:usersdddocumentsvisual studio 2010projectscs201program5program5program5.cpp(52): warning C4715: 'palcheck' : not all control paths return a value
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:UsersddDocumentsVisual Studio 2010ProjectsCS201program5Debugprogram5.exe : fatal error LNK1120: 1 unresolved externals

any ideas?

#include<iostream>
#include<fstream>
#include<string>
using namespace std;



bool palcheck(string word, int first, int last);

int main()
{
ofstream palindrome, NOTpalindrome;
ifstream fin;
string word;

palindrome.open("palindrontest.txt");
NOTpalindrome.open("notPalindronetest.txt");
fin.open("input5.txt"); //list of palindromes, one per line

if (palindrome.fail() || NOTpalindrome.fail() || fin.fail())
return -1;

while (fin >> word)
{
if (palcheck(word, 0, (word.size()-1)) == true)
palindrome << word << endl;
else
NOTpalindrome << word << endl;
}

palindrome.close();
NOTpalindrome.close();
fin.close();


return 0;
}


bool palcheck(string word, int first, int last)
{
if (first >= last)
return true;

else if (word[first] == word[last])
return palcheck(word, first+1, last-1);

else// (word[first] != word[last])
return false;

}
Last edited on
When telling us compiler errors, it does help to know what compiler you are using. Also, the complete quote would be good, for example if it shows a line the compiler determined the error to occur in, or maybe it isn't even a compiler but a linker error... etc.

Oh, and use [ code] [ /code] tags please.
Think carefully about all the possible execution paths in the palcheck function and make sure a value is returned at the end of each one. (At the moment I think a value is returned by only two out of four.

Also you seem to have put a conditional statement after else. I don't think you can do this. You must instead use another else if.

Hope this helps.
thanks xander. ive made a couple changes but still getting the same errors. see above
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

this is the real issue here. You are trying to compile it as a Win32 project but don't provide a WinMain function.

PS: [ code] at the beginning of your code, [ /code] at the end of your code. You're new to this forum thingy, aren't you? ;)
Last edited on
good call sir. i merely made a new project entirely with my existing cpp file, and now all is well. thank you all so much for your consideration and your expertise. hopefully i can do the same one day.
lol is it that obvious!? ...apparently... thanks for the tip though. now on to new mistakes!
Topic archived. No new replies allowed.