Hey all,

I've spent the last couple hours looking at other posts with the same error and have still yet to figure out what is wrong. I'm just learning C++, I have a bit of experience with Python but, still just getting my feet wet.

Here is the code.

#include "stdafx.h"
#include <iostream>
using namespace std;


int winmain()
{
	cout << "Palindrome Test" << endl;
	char *charlist;
	//Pointer for the array, so the user can specify the size.
	int numchars;
	//Variable for the number of characters in the array
	numchars = 5;
	//Initializing numchars
	int counter,counter2;
	//Two int counters, one to count up and one to count backwards
	charlist = new char [numchars-1];
	//Create array charlist
	
	bool paltest;
	paltest = true;
	//Boolian variable, used for whether the string is a palindrome or not
	
	int Inputstring ( );
	
	
	{
		cout << "How many characters are in your string?" << endl;
		cin >> numchars;
		//Sets user defined number of characters
		cout << "Enter in the characters you would like to test:" << endl;
		for ( counter = 0; counter < numchars; counter++)
		{
			cin>>charlist[counter];
			cout << charlist[counter];
		}
		//Input the user's characters into string and print string to verify it is correct
		cout << endl;
		
		return 0;

	}


	
	bool PalindromeTest ( );
	{
		counter2 = numchars-1;
		//Set counter 2 to user specified number of characters
		for (counter = 0; counter < numchars/2; counter++)
		{
			if ( charlist[counter] == charlist[counter2] )
			{	
				cout << "Match: " << charlist[counter] << "," << charlist [counter2] << endl;
				counter2 = counter2--;
				continue;
				//If the characters in the nth position from start and from the end are the same, it is still a palindrome, print the characters and continue.
			}
			else
			{	
				paltest = false ;
				cout << "No Match: " << charlist[counter] << "," << charlist[counter2] << endl;
				break;
				//If the characters in the nth position from start and from the end aren't the same, stop checking for palindrome, its false.
			}	
			
		

			system ("pause");
			return paltest;
	
		}
	

	}
	bool m = PalindromeTest ();
	cout << m << endl;
	//Call function Palindromeest
	
	char PrintMessage ( m );
		{
			switch ( m )
			{
			case (true):
					cout << " is a palindrome!" << endl;
			case (false): 
					cout << " is not a palindrome!" << endl;
		
		
			}
			return 0;
		}
	

	
	system ("pause");
	return 0;
}

and the error messages


1>------ Build started: Project: palindrome, Configuration: Debug Win32 ------
1> palindrome.cpp
1>palindrome.obj : error LNK2019: unresolved external symbol "bool __cdecl PalindromeTest(void)" (?PalindromeTest@@YA_NXZ) referenced in function "int __cdecl winmain(void)" (?winmain@@YAHXZ)
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\documents\palindrome: fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I've tried switching main to winmain, and also changing it from a console application to a win32 application. Neither of these helped, anything would be great, even a point to another forum that discusses the problem in more depth.

Mike

You're either trying to declare or implement functions inside your main function, that's not a good idea. Functions should be first declared outside of main function:

bool PalindromeTest( );

and then implemented, usually after main function

bool PalindromeTest ( )
{
 // implementation
}

Note: no semicolon in implementation.

Now they can be called in your main function.

That makes since I fixed that. But I am still getting a similar issue. I'm sure this is due to my formating of the functions as well.

// mikeashlecturehw2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


char *charlist;
//Pointer for the array, so the user can specify the size.
int numchars = 5;
//Initializing numchars
int counter,counter2;
//Two int counters, one to count up and one to count backwards
bool paltest = true;
//Boolian variable, used for whether the string is a palindrome or	


int Inputstring ( )	
{
	charlist = new char [numchars-1];
	//Create array charlist
	cout << "How many characters are in your string?" << endl;
	cin >> numchars;
	//Sets user defined number of characters
	cout << "Enter in the characters you would like to test:" << endl;
	for ( counter = 0; counter < numchars; counter++)
	{
		cin>>charlist[counter];
		cout << charlist[counter];
	}
	//Input the user's characters into string and print string to verify it is correct
	cout << endl;
		
	return charlist, numchars;

}

bool PalindromeTest ( )
{
	counter2 = numchars-1;
	//Set counter 2 to user specified number of characters
	for (counter = 0; counter < numchars/2; counter++)
	{
		if ( charlist[counter] == charlist[counter2] )
		{	
			cout << "Match: " << charlist[counter] << "," << charlist [counter2] << endl;
			counter2 = counter2--;
			continue;
			//If the characters in the nth position from start and from the end are the same, it is still a palindrome, print the characters and continue.
		}
		else
		{	
			paltest = false ;
			cout << "No Match: " << charlist[counter] << "," << charlist[counter2] << endl;
			break;
			//If the characters in the nth position from start and from the end aren't the same, stop checking for palindrome, its false.
		}	
	}
	return paltest;
}
int PrintMessage ( )
{	bool m = paltest;
	switch ( m )
	{
		case (true):
			cout << " is a palindrome!" << endl;
		case (false): 
			cout << " is not a palindrome!" << endl;
	}
	return 0;
}

int winmain()

{
	cout << "Palindrome Test" << endl;
	int x = Inputstring ( );
	cout << x << endl;
	bool m = PalindromeTest ();
	cout << m << endl;
	int k = PrintMessage ();
	cout << k << endl;
	//Call function Palindromeest
	

	
	system ("pause");
	return 0;

}

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

I figured it out, I had changed my subsystem settings when I was trouble shooting earlier. I changed them back to console from windows. Thank you very much for you quick response. Working great now : D, after I tweaked the switch statement too.

This question has already been answered. Start a new discussion instead.