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;
}