Student Problem:
"I am trying to get the code below to compile which is from my textbook "C++ How To Program (6th Edition)" Fig. 4.9.

However, I keep getting the "Fatal Error LNK1561: Entry Point Must Be Defined" every time I try to build the code."

What I Know So Far:
"My understanding of this error is that I do not have any main() to tell the compiler where to start the program."

How I Need Help:
"Please help me understand where I need my main() and why."

// Fig. 4.9: GradeBook.cpp
// Member-function definitions for class GradeBook that solves the
// class average program with counter-controlled repetition.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "GradeBook.h" // Include definition of class GradeBook
// Constructor initializes courseName with string supplied as argument
GradeBook::GradeBook( string name )
{
	setCourseName ( name ) ; // Validate and store courseName
} // End GradeBook constructor

// Function to set the course name;
// ensures that the course name has at most 25 characters
void GradeBook::setCourseName( string name )
{
	if ( name.length( ) <= 25 ) // If name has 25 or fewer characters
		courseName = name ; // Store the course name in the object
	else // if name is longer than 25 characters
	{ // Set courseName to first 25 characters of parameter name
		courseName = name.substr( 0,25 ) ; // Selects first 25 characters
		cout << "Name \"" << name << "\" exceeds maximum length (of 25 characters).\n"
			<< "Limiting courseName to first 25 characters.\n" << endl ;
	} // End if...else
} // End function setCourseName

// Function to retrieve the course name
string GradeBook::getCourseName( )
{
	return courseName ;
} // End function getCourseName

// Display a welcome message to the GradeBook user
void GradeBook::displayMessage( )
{
	cout << "Welcome to the grade book for\n" << getCourseName( ) << "!\n" 
		<< endl ;
} // End function displayMessage

// Determine class average based on 10 grades entered by user
void GradeBook::determineClassAverage( )
{
	int total ; // Sum of grades entered by user
	int gradeCounter ; // Number of the grade to be entered next
	int grade ; // Grade value entered by user
	int average ; // average of grades

	// Initialization phase
	total = 0 ; // Initialize total
	gradeCounter = 1 ; // Initialize loop counter

	// Processing phase
	while ( gradeCounter <= 10 ) // Loop 10 times
	{
		cout << "Enter grade: " ; // Prompt for input
		cin >> grade ; // Input next grade
		total = total + grade ; // Add grade to total
		gradeCounter = gradeCounter + 1 ; // Increment counter by 1
	} // End while

	// Termination phase
	average = total / 10 ; // Integer division yields integer result

	// Display total and average of grades
	cout << "\nTotal of all 10 grades is " << total << endl ;
	cout << "Class average is " << average << endl ;
} // End function determineClassAverage

You need a main() that will put all the functions to use. Call the functions in main(). Start it with:

int main()
{
//call functions and write other code
return 0;
} // closes main
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.