LNK2019: unresolved external

Error in compiler

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1505 Views - Last Post: 27 August 2008 - 09:09 PM Rate Topic: -----

#16 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: LNK2019: unresolved external

Posted 25 August 2008 - 11:45 AM

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.
Was This Post Helpful? 0
  • +
  • -

#17 tyserman474  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 77
  • Joined: 28-March 08

Re: LNK2019: unresolved external

Posted 25 August 2008 - 03:01 PM

View PostNickDMax, on 25 Aug, 2008 - 11:45 AM, said:

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.


Thanks you so much Nick. I changed the code and submitted it. I works great and is exactly what I needed.
For this coming week I just have to add to display the amortization schedule, which I have coded just have to work it into this one.
Thanks Again,
Ken
Was This Post Helpful? 0
  • +
  • -

#18 tyserman474  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 77
  • Joined: 28-March 08

Re: LNK2019: unresolved external

Posted 26 August 2008 - 08:09 AM

View Posttyserman474, on 25 Aug, 2008 - 03:01 PM, said:

View PostNickDMax, on 25 Aug, 2008 - 11:45 AM, said:

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.


Thanks you so much Nick. I changed the code and submitted it. I works great and is exactly what I needed.
For this coming week I just have to add to display the amortization schedule, which I have coded just have to work it into this one.
Thanks Again,
Ken

Nick,
I have a question for you. Maybe you will explain it to me so I can understand it, I sure wish if you where my instructor.
In the following code code I get 3 errors, "undeclared indenifier" and I can't figure out why. I have the code placed right under'
morgCalc.Amortization();

and they are called out at the bottom in.
void MortgageCal::Amortization()

I don't understand why I am getting them. if you can mybe explain why for me this whole thing will come together. I would really like to learn C++ but I am sure missing something.
Here is my whole code. The program did work until I had to add to show the amortization schedule over the term of the loan.
	/*  Week 2 Individual Assignment
	PRG 411
	Written By: Ken Volkman
	Date: 08/25/2008
	File Name: MC_PRG411_Final_WK2
	Purpose: To calculate the amount a Mortgage Payement will be from
	user input values.
*/
	#include <iostream>	// Library defines facilities for basic I/O operations...
	#include <iomanip>		// Libaray for stream manipulators...
	#include <string>		// Library for accepting stings...
	#include <limits>		// Library for setting limits...  
		  
	using namespace std;	// Standard using definitions...
		   
	class MortgageCal   
	{	
		private:	
			double intYear;	 // interest rate per year...	
			double intMonth;	// interest converted to months...	
			double loanAmt;	 // amount of the loan...	
			double term;		// term in years...	
			double numMonths;   // term converted to months...	
			double paymentAmt;  // variable for monthly payment...	
			double balance;	 // running total...	
			double principleAmt;// amount towards loan...	
			double amtMortgage; // total amount to be paid back...  
	  
		public:  
	  
			// Constructor, initializes any unpassed value to zero...  
			MortgageCal(  
				double intYear = 0,   
				double term = 0,  
				double loanAmt = 0,  
				double paymentAmt = 0,  
				double numMonths = 0,  
				double intMonth = 0,  
				double balance = 0,  
				double principleAmt = 0,  
				double amtMortgage = 0) :  
				intYear(intYear),  
				term(term),  
				loanAmt(loanAmt),  
				paymentAmt(paymentAmt),  
				numMonths(),  
				intMonth(),  
				balance(),  
				principleAmt(),  
				amtMortgage() { }

			  
			// get and set for data elements... 
			double getIntYear() { return intYear; }  
			bool setIntYear(double year) { intYear = year; return true; }  
			double getTermInMonths() { return intYear * 12; } // preform calculations...  
			bool setTermInMonths(double months) 
			{  
				if (months > 0) { intYear = months/12; }  
				else { return false; }  
				return true;  
			}  
			double getTermInYears() { return term; }  
			bool setTermInYears(double years) 
			{   
				if (years > 0) { term = years; }  
				else { return false; }  
				return true;  
			}  
			double getPrinciple() { return principleAmt;}  
			bool setPrinciple(double principle)
			{  
				if (principle >= 0) { principleAmt = principle; }  
				else { return false; }  
				return true;  
			}  
			double getLoanAmount(){ return loanAmt; }  
			bool setLoanAmount(double loan)  
			{  
				if (loan >= 0) { loanAmt = loan; }  
				else { return false; }  
				return true;  
			}
			
			double getPaymentAmount() { return paymentAmt; }		  
			bool setYearlyRate(double rate) 
			{ intYear = rate;   
				return true;
			}
	  
			//Declarations for other member functions...  
		   void Amortization();  
	};  // end class
	  
	// function to get input from the user...   
	double getRangedInput(const string prompt, double min, double max, int tries = 5);  
	void pause(); //pause  
	  
	//main() function. Controls the main logic needed to interface with the user...

	int main() 
	{  
		double loanAmount;		// Initialize original amount of loan...
		double term;			// Initialize term of loan in years...
		double yearlyRate;		// Initialize interest rate of loan...

		MortgageCal morgCalc;	// Redefine class as subclass...
		char indicator = 'y';	// set indicator to 'y' for continue...
		while ((indicator =='y') || (indicator == 'Y')) // to continue loop as long as input = y
		{		  
		/*get and set all of the input from the user/ranges...
		 Set up screen output to display mortgage amount, interest 
		rate and term of loan...*/
		loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());  
		cout << endl;
		term = getRangedInput("Please enter the loan term in years", 0, 10000);  
		cout << endl;
		yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);  
		cout << endl;
		morgCalc.setLoanAmount(loanAmount);  
		morgCalc.setTermInYears(term);  
		morgCalc.setYearlyRate(yearlyRate);  
					
		//display the payment calculations...  
		morgCalc.Amortization();
		{
		cout << "After Amortinzation:\n"
			 << endl
			 << "Your payments will be: $" << morgCalc.getPaymentAmount() << endl  
			 << endl;  
				 
	  
			cout << endl  
				 << "This is a breakdown of "  
				 << "how much of your payment is applied " << endl;  
			cout << "to interest and the "  
				 << "balance of your loan: " << endl;  
				 system ( "PAUSE" );  
			cout << endl << endl; // headings  
			cout << " Payment" << setw(15) << "Interest"  
				 << endl;  
			cout << " Number " << setw(15) << "  Paid  "  
				 << setw(14) << "balance " << endl;  
			cout << " _______" << setw(15) << "________"  
				 << setw(14) << "________" << endl;  
	  
			int intPymtNum = 1;			 // counter for payments  
			int max = 0;					// displays maximum lines on screen  
			double intRate = 0.0;		 // calculated loan interest  
			double intPayment = 0.0;		 // interest amount applied to loan  
			double principleAmt = 0.0;   // principle amount applied to loan  
			double loanBal = 0.0;		// running balance of loan  
			loanBal = loanAmount;	  // used for running total*/ 
	  
			for(int i = 1, max = 1; intPymtNum <= numMonths; i++)  
			{   // controls the loop of monthly payments  
				intRate = intMonth; //intMonth;  
				intPayment = loanBal * intRate;  
				principleAmt = paymentAmt - (loanBal * intRate);  
				loanBal = loanBal - principleAmt;  
	  
				if (loanBal <= 0)  
				{  
					loanBal = 0;  // to avoid negative numbers  
				}  
				cout << endl  
					 << setw(5) << intPymtNum << setw(17)  
					 << intPayment << setw(15) << loanBal;  
				intPymtNum++;		   // adds 1 to payment number  
				max++;				  // adds 1 to line count */ 
			
				if (max == 20)  
					{				   // loop pauses program every 20 lines  
						cout << endl;  
						system ( "PAUSE" );  
						//max = 1;				// resets line count  
						cout << endl << endl;   // prints headings again  
						cout << " Payment" << setw(15) << "Interest"  
							 << endl;  
						cout << " Number " << setw(15) << "  Paid  "  
							 << setw(14) << "balance " << endl;  
						cout << " _______" << setw(15) << "________"  
							 << setw(14) << "________" << endl;  
					} // end if loop  
			} // end for loop  
		} // end Print_List()  
		
		pause(); // to get user input to enter new values...
		cout << endl;			// Enter newline...
		//Set up screen for input on whether to enter new numbers or exit...
		cout << "Do you want to enter another value (enter y to continue or n to end)? "; 
		cin >> indicator;		// Read indicator input...
		cout << endl;
		} // end while
		
		cout << endl;
		cout << "\"Thank you for using our mortgage calculator\"" << endl;
		cout << endl;
		return 0;  // End program...
	}  
	  
	/** 
	 *Function for getting input from the user. 
	 * If the user enters an invalid string, or if the user enters a value outside of the  
	 * given range then it will give the user an error message... 
	 */  
	double getRangedInput(const string prompt, double min, double max, int tries) 
	{  
		int userTry = 0;  
		double userInVal = 0;  
		bool isValidInput;  
		do {  
			cout << prompt << ": ";  
			cin >> userInVal;  
			if (!cin.good()) 
			{
				cout <<endl;
				cout << "INPUT ERROR: Please input a proper number!" << endl;  
				cin.clear();  
				cin.ignore(numeric_limits<streamsize>::max(), '\n');  
				isValidInput = false;  
			} else 
			{  
				isValidInput = (userInVal >= min && userInVal <= max);  
			}  
			if (!isValidInput) 
			{  
				cout << "Please enter a value between " << min << " and " << max << "!" << endl;  
				cout << endl;
			}  
		  } while (!isValidInput && ++userTry < tries); // end while... 
		if (userTry == tries) 
		{  
			cout << "User input invalid, can not process!" << endl;  
			exit(1); //If the user can't input a valid value, exit the program...   
		}  
		return userInVal;  
	  
	}  // end of get for error input...
	  
	void pause() 
	{	
		cout << "Press enter to continue...";  
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
		cin.ignore();  
	}  
	  
	/*define member functions...
	Determines monthly interest in decimal format
	Set up monthly payment calculations...*/
		
	void MortgageCal::Amortization() 
	{  
		numMonths = term * 12;	  // Converts years to months...   
		intMonth = intYear/1200;	// Converts annual rate to monthly rate...	
		paymentAmt = (loanAmt*intMonth)/(1-pow(1+intMonth,-numMonths)); // Amortization formula...  

	}  



I may have parts of this in the wrong place but it just doesn't make sense to me.
Thanks a million Nick and like I said I sure wish that you where my instructor.
Ken
Thanks a million Nick and like I said I wish that you where my instructor.

*edit: fixed code tags: :code: <--- note how the closing take has the / in it!

This post has been edited by NickDMax: 26 August 2008 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#19 tyserman474  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 77
  • Joined: 28-March 08

Re: LNK2019: unresolved external

Posted 26 August 2008 - 08:32 AM

View Posttyserman474, on 26 Aug, 2008 - 08:09 AM, said:

View Posttyserman474, on 25 Aug, 2008 - 03:01 PM, said:

View PostNickDMax, on 25 Aug, 2008 - 11:45 AM, said:

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.


Thanks you so much Nick. I changed the code and submitted it. I works great and is exactly what I needed.
For this coming week I just have to add to display the amortization schedule, which I have coded just have to work it into this one.
Thanks Again,
Ken

Nick,
I have a question for you. Maybe you will explain it to me so I can understand it, I sure wish if you where my instructor.
In the following code code I get 3 errors, "undeclared indenifier" and I can't figure out why. I have the code placed right under'
[code]
morgCalc.Amortization();
[code]
and they are called out at the bottom in.
[code]
void MortgageCal::Amortization()
[code]
I don't understand why I am getting them. if you can mybe explain why for me this whole thing will come together. I would really like to learn C++ but I am sure missing something.
Here is my whole code. The program did work until I had to add to show the amortization schedule over the term of the loan.
[code]
/* Week 2 Individual Assignment
PRG 411
Written By: Ken Volkman
Date: 08/25/2008
File Name: MC_PRG411_Final_WK2
Purpose: To calculate the amount a Mortgage Payement will be from
user input values.
*/
#include <iostream> // Library defines facilities for basic I/O operations...
#include <iomanip> // Libaray for stream manipulators...
#include <string> // Library for accepting stings...
#include <limits> // Library for setting limits...

using namespace std; // Standard using definitions...

class MortgageCal
{
private:
double intYear; // interest rate per year...
double intMonth; // interest converted to months...
double loanAmt; // amount of the loan...
double term; // term in years...
double numMonths; // term converted to months...
double paymentAmt; // variable for monthly payment...
double balance; // running total...
double principleAmt;// amount towards loan...
double amtMortgage; // total amount to be paid back...

public:

// Constructor, initializes any unpassed value to zero...
MortgageCal(
double intYear = 0,
double term = 0,
double loanAmt = 0,
double paymentAmt = 0,
double numMonths = 0,
double intMonth = 0,
double balance = 0,
double principleAmt = 0,
double amtMortgage = 0) :
intYear(intYear),
term(term),
loanAmt(loanAmt),
paymentAmt(paymentAmt),
numMonths(),
intMonth(),
balance(),
principleAmt(),
amtMortgage() { }


// get and set for data elements...
double getIntYear() { return intYear; }
bool setIntYear(double year) { intYear = year; return true; }
double getTermInMonths() { return intYear * 12; } // preform calculations...
bool setTermInMonths(double months)
{
if (months > 0) { intYear = months/12; }
else { return false; }
return true;
}
double getTermInYears() { return term; }
bool setTermInYears(double years)
{
if (years > 0) { term = years; }
else { return false; }
return true;
}
double getPrinciple() { return principleAmt;}
bool setPrinciple(double principle)
{
if (principle >= 0) { principleAmt = principle; }
else { return false; }
return true;
}
double getLoanAmount(){ return loanAmt; }
bool setLoanAmount(double loan)
{
if (loan >= 0) { loanAmt = loan; }
else { return false; }
return true;
}

double getPaymentAmount() { return paymentAmt; }
bool setYearlyRate(double rate)
{ intYear = rate;
return true;
}

//Declarations for other member functions...
void Amortization();
}; // end class

// function to get input from the user...
double getRangedInput(const string prompt, double min, double max, int tries = 5);
void pause(); //pause

//main() function. Controls the main logic needed to interface with the user...

int main()
{
double loanAmount; // Initialize original amount of loan...
double term; // Initialize term of loan in years...
double yearlyRate; // Initialize interest rate of loan...

MortgageCal morgCalc; // Redefine class as subclass...
char indicator = 'y'; // set indicator to 'y' for continue...
while ((indicator =='y') || (indicator == 'Y')) // to continue loop as long as input = y
{
/*get and set all of the input from the user/ranges...
Set up screen output to display mortgage amount, interest
rate and term of loan...*/
loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
cout << endl;
term = getRangedInput("Please enter the loan term in years", 0, 10000);
cout << endl;
yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
cout << endl;
morgCalc.setLoanAmount(loanAmount);
morgCalc.setTermInYears(term);
morgCalc.setYearlyRate(yearlyRate);

//display the payment calculations...
morgCalc.Amortization();
{
cout << "After Amortinzation:\n"
<< endl
<< "Your payments will be: $" << morgCalc.getPaymentAmount() << endl
<< endl;


cout << endl
<< "This is a breakdown of "
<< "how much of your payment is applied " << endl;
cout << "to interest and the "
<< "balance of your loan: " << endl;
system ( "PAUSE" );
cout << endl << endl; // headings
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;

int intPymtNum = 1; // counter for payments
int max = 0; // displays maximum lines on screen
double intRate = 0.0; // calculated loan interest
double intPayment = 0.0; // interest amount applied to loan
double principleAmt = 0.0; // principle amount applied to loan
double loanBal = 0.0; // running balance of loan
loanBal = loanAmount; // used for running total*/

for(int i = 1, max = 1; intPymtNum <= numMonths; i++)
{ // controls the loop of monthly payments
intRate = intMonth; //intMonth;
intPayment = loanBal * intRate;
principleAmt = paymentAmt - (loanBal * intRate);
loanBal = loanBal - principleAmt;

if (loanBal <= 0)
{
loanBal = 0; // to avoid negative numbers
}
cout << endl
<< setw(5) << intPymtNum << setw(17)
<< intPayment << setw(15) << loanBal;
intPymtNum++; // adds 1 to payment number
max++; // adds 1 to line count */

if (max == 20)
{ // loop pauses program every 20 lines
cout << endl;
system ( "PAUSE" );
//max = 1; // resets line count
cout << endl << endl; // prints headings again
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;
} // end if loop
} // end for loop
} // end Print_List()

pause(); // to get user input to enter new values...
cout << endl; // Enter newline...
//Set up screen for input on whether to enter new numbers or exit...
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input...
cout << endl;
} // end while

cout << endl;
cout << "\"Thank you for using our mortgage calculator\"" << endl;
cout << endl;
return 0; // End program...
}

/**
*Function for getting input from the user.
* If the user enters an invalid string, or if the user enters a value outside of the
* given range then it will give the user an error message...
*/
double getRangedInput(const string prompt, double min, double max, int tries)
{
int userTry = 0;
double userInVal = 0;
bool isValidInput;
do {
cout << prompt << ": ";
cin >> userInVal;
if (!cin.good())
{
cout <<endl;
cout << "INPUT ERROR: Please input a proper number!" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
isValidInput = false;
} else
{
isValidInput = (userInVal >= min && userInVal <= max);
}
if (!isValidInput)
{
cout << "Please enter a value between " << min << " and " << max << "!" << endl;
cout << endl;
}
} while (!isValidInput && ++userTry < tries); // end while...
if (userTry == tries)
{
cout << "User input invalid, can not process!" << endl;
exit(1); //If the user can't input a valid value, exit the program...
}
return userInVal;

} // end of get for error input...

void pause()
{
cout << "Press enter to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.ignore();
}

/*define member functions...
Determines monthly interest in decimal format
Set up monthly payment calculations...*/

void MortgageCal::Amortization()
{
numMonths = term * 12; // Converts years to months...
intMonth = intYear/1200; // Converts annual rate to monthly rate...
paymentAmt = (loanAmt*intMonth)/(1-pow(1+intMonth,-numMonths)); // Amortization formula...

}

[code]
I may have parts of this in the wrong place but it just doesn't make sense to me.
Thanks a million Nick and like I said I sure wish that you where my instructor.
Ken
Thanks a million Nick and like I said I wish that you where my instructor.

Nick,
I forgot to ment tion the 3 indentifiers are:
numMonths, intMonth and paymentAmt.
Ken
Was This Post Helpful? 0
  • +
  • -

#20 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: LNK2019: unresolved external

Posted 26 August 2008 - 06:01 PM

You get undeclared identifier because you are trying to use identifiers that are not defined within the current scope. They maybe defined within the program, but not within the current scope.
Was This Post Helpful? 0
  • +
  • -

#21 tyserman474  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 77
  • Joined: 28-March 08

Re: LNK2019: unresolved external

Posted 26 August 2008 - 08:32 PM

View Posttyserman474, on 26 Aug, 2008 - 08:32 AM, said:

View Posttyserman474, on 26 Aug, 2008 - 08:09 AM, said:

View Posttyserman474, on 25 Aug, 2008 - 03:01 PM, said:

View PostNickDMax, on 25 Aug, 2008 - 11:45 AM, said:

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.


Thanks you so much Nick. I changed the code and submitted it. I works great and is exactly what I needed.
For this coming week I just have to add to display the amortization schedule, which I have coded just have to work it into this one.
Thanks Again,
Ken

Nick,
I have a question for you. Maybe you will explain it to me so I can understand it, I sure wish if you where my instructor.
In the following code code I get 3 errors, "undeclared indenifier" and I can't figure out why. I have the code placed right under'
[code]
morgCalc.Amortization();
[code]
and they are called out at the bottom in.
[code]
void MortgageCal::Amortization()
[code]
I don't understand why I am getting them. if you can mybe explain why for me this whole thing will come together. I would really like to learn C++ but I am sure missing something.
Here is my whole code. The program did work until I had to add to show the amortization schedule over the term of the loan.
[code]
/* Week 2 Individual Assignment
PRG 411
Written By: Ken Volkman
Date: 08/25/2008
File Name: MC_PRG411_Final_WK2
Purpose: To calculate the amount a Mortgage Payement will be from
user input values.
*/
#include <iostream> // Library defines facilities for basic I/O operations...
#include <iomanip> // Libaray for stream manipulators...
#include <string> // Library for accepting stings...
#include <limits> // Library for setting limits...

using namespace std; // Standard using definitions...

class MortgageCal
{
private:
double intYear; // interest rate per year...
double intMonth; // interest converted to months...
double loanAmt; // amount of the loan...
double term; // term in years...
double numMonths; // term converted to months...
double paymentAmt; // variable for monthly payment...
double balance; // running total...
double principleAmt;// amount towards loan...
double amtMortgage; // total amount to be paid back...

public:

// Constructor, initializes any unpassed value to zero...
MortgageCal(
double intYear = 0,
double term = 0,
double loanAmt = 0,
double paymentAmt = 0,
double numMonths = 0,
double intMonth = 0,
double balance = 0,
double principleAmt = 0,
double amtMortgage = 0) :
intYear(intYear),
term(term),
loanAmt(loanAmt),
paymentAmt(paymentAmt),
numMonths(),
intMonth(),
balance(),
principleAmt(),
amtMortgage() { }


// get and set for data elements...
double getIntYear() { return intYear; }
bool setIntYear(double year) { intYear = year; return true; }
double getTermInMonths() { return intYear * 12; } // preform calculations...
bool setTermInMonths(double months)
{
if (months > 0) { intYear = months/12; }
else { return false; }
return true;
}
double getTermInYears() { return term; }
bool setTermInYears(double years)
{
if (years > 0) { term = years; }
else { return false; }
return true;
}
double getPrinciple() { return principleAmt;}
bool setPrinciple(double principle)
{
if (principle >= 0) { principleAmt = principle; }
else { return false; }
return true;
}
double getLoanAmount(){ return loanAmt; }
bool setLoanAmount(double loan)
{
if (loan >= 0) { loanAmt = loan; }
else { return false; }
return true;
}

double getPaymentAmount() { return paymentAmt; }
bool setYearlyRate(double rate)
{ intYear = rate;
return true;
}

//Declarations for other member functions...
void Amortization();
}; // end class

// function to get input from the user...
double getRangedInput(const string prompt, double min, double max, int tries = 5);
void pause(); //pause

//main() function. Controls the main logic needed to interface with the user...

int main()
{
double loanAmount; // Initialize original amount of loan...
double term; // Initialize term of loan in years...
double yearlyRate; // Initialize interest rate of loan...

MortgageCal morgCalc; // Redefine class as subclass...
char indicator = 'y'; // set indicator to 'y' for continue...
while ((indicator =='y') || (indicator == 'Y')) // to continue loop as long as input = y
{
/*get and set all of the input from the user/ranges...
Set up screen output to display mortgage amount, interest
rate and term of loan...*/
loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
cout << endl;
term = getRangedInput("Please enter the loan term in years", 0, 10000);
cout << endl;
yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
cout << endl;
morgCalc.setLoanAmount(loanAmount);
morgCalc.setTermInYears(term);
morgCalc.setYearlyRate(yearlyRate);

//display the payment calculations...
morgCalc.Amortization();
{
cout << "After Amortinzation:\n"
<< endl
<< "Your payments will be: $" << morgCalc.getPaymentAmount() << endl
<< endl;


cout << endl
<< "This is a breakdown of "
<< "how much of your payment is applied " << endl;
cout << "to interest and the "
<< "balance of your loan: " << endl;
system ( "PAUSE" );
cout << endl << endl; // headings
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;

int intPymtNum = 1; // counter for payments
int max = 0; // displays maximum lines on screen
double intRate = 0.0; // calculated loan interest
double intPayment = 0.0; // interest amount applied to loan
double principleAmt = 0.0; // principle amount applied to loan
double loanBal = 0.0; // running balance of loan
loanBal = loanAmount; // used for running total*/

for(int i = 1, max = 1; intPymtNum <= numMonths; i++)
{ // controls the loop of monthly payments
intRate = intMonth; //intMonth;
intPayment = loanBal * intRate;
principleAmt = paymentAmt - (loanBal * intRate);
loanBal = loanBal - principleAmt;

if (loanBal <= 0)
{
loanBal = 0; // to avoid negative numbers
}
cout << endl
<< setw(5) << intPymtNum << setw(17)
<< intPayment << setw(15) << loanBal;
intPymtNum++; // adds 1 to payment number
max++; // adds 1 to line count */

if (max == 20)
{ // loop pauses program every 20 lines
cout << endl;
system ( "PAUSE" );
//max = 1; // resets line count
cout << endl << endl; // prints headings again
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;
} // end if loop
} // end for loop
} // end Print_List()

pause(); // to get user input to enter new values...
cout << endl; // Enter newline...
//Set up screen for input on whether to enter new numbers or exit...
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input...
cout << endl;
} // end while

cout << endl;
cout << "\"Thank you for using our mortgage calculator\"" << endl;
cout << endl;
return 0; // End program...
}

/**
*Function for getting input from the user.
* If the user enters an invalid string, or if the user enters a value outside of the
* given range then it will give the user an error message...
*/
double getRangedInput(const string prompt, double min, double max, int tries)
{
int userTry = 0;
double userInVal = 0;
bool isValidInput;
do {
cout << prompt << ": ";
cin >> userInVal;
if (!cin.good())
{
cout <<endl;
cout << "INPUT ERROR: Please input a proper number!" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
isValidInput = false;
} else
{
isValidInput = (userInVal >= min && userInVal <= max);
}
if (!isValidInput)
{
cout << "Please enter a value between " << min << " and " << max << "!" << endl;
cout << endl;
}
} while (!isValidInput && ++userTry < tries); // end while...
if (userTry == tries)
{
cout << "User input invalid, can not process!" << endl;
exit(1); //If the user can't input a valid value, exit the program...
}
return userInVal;

} // end of get for error input...

void pause()
{
cout << "Press enter to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.ignore();
}

/*define member functions...
Determines monthly interest in decimal format
Set up monthly payment calculations...*/

void MortgageCal::Amortization()
{
numMonths = term * 12; // Converts years to months...
intMonth = intYear/1200; // Converts annual rate to monthly rate...
paymentAmt = (loanAmt*intMonth)/(1-pow(1+intMonth,-numMonths)); // Amortization formula...

}

[code]
I may have parts of this in the wrong place but it just doesn't make sense to me.
Thanks a million Nick and like I said I sure wish that you where my instructor.
Ken
Thanks a million Nick and like I said I wish that you where my instructor.

Nick,
I forgot to ment tion the 3 indentifiers are:
numMonths, intMonth and paymentAmt.
Ken

Thanks Nick for all, I will see if I can figure it out. I don't know why but this is sure tough for me. I did good in Java and just C++, but tryng to go to OOP in C++ there is just something that isn't clicking.
Thanks,
Ken
Was This Post Helpful? 0
  • +
  • -

#22 tyserman474  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 77
  • Joined: 28-March 08

Re: LNK2019: unresolved external

Posted 27 August 2008 - 09:09 PM

View Posttyserman474, on 26 Aug, 2008 - 08:32 PM, said:

View Posttyserman474, on 26 Aug, 2008 - 08:32 AM, said:

View Posttyserman474, on 26 Aug, 2008 - 08:09 AM, said:

View Posttyserman474, on 25 Aug, 2008 - 03:01 PM, said:

View PostNickDMax, on 25 Aug, 2008 - 11:45 AM, said:

You need to think things though more logically. Each line of code has a purpose, it gets you closer to your solution.

pause();
// What does this next line accomplish? 
//char indicator = ('y', 'Y', 'n', 'N');
// it sets indicatior == 'N' (look up the comma operator in C/C++)
// does this help? Well maybe but is can be simplified to:
char indicator = 'N';
do
{
cout << endl; // Enter newline
//Set up screen for input on rather to enter new numbers or exit
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input

//What do we need to continue? Well a value of 'y' or 'Y'
// Lets only work with upper case... since it simplifies our work.
indicator = toupper(indicator);

//Now check to see what the user entered, was it something valid?
if (indicator != 'N' || indicator != 'Y') {
	cout  << "You did not answer y or n, assuming answer of n";
	indicator = 'N';
}

//Now to know if we need to exit the loop all we need to see if indicator == 'Y' 
// if true then we loop, else we exit the loop.
} while (indicator == 'Y'); // end do loop

return 0; 


THINK! Think about each line of code, how does it help you reach your goal. What is the simplest way to get to your goal. Programming is just taking baby steps, solve little problems that help you solve larger ones.

Go back over your code as your write it. Run it in your head. Compile often making only small changes.


Thanks you so much Nick. I changed the code and submitted it. I works great and is exactly what I needed.
For this coming week I just have to add to display the amortization schedule, which I have coded just have to work it into this one.
Thanks Again,
Ken

Nick,
I have a question for you. Maybe you will explain it to me so I can understand it, I sure wish if you where my instructor.
In the following code code I get 3 errors, "undeclared indenifier" and I can't figure out why. I have the code placed right under'
[code]
morgCalc.Amortization();
[code]
and they are called out at the bottom in.
[code]
void MortgageCal::Amortization()
[code]
I don't understand why I am getting them. if you can mybe explain why for me this whole thing will come together. I would really like to learn C++ but I am sure missing something.
Here is my whole code. The program did work until I had to add to show the amortization schedule over the term of the loan.
[code]
/* Week 2 Individual Assignment
PRG 411
Written By: Ken Volkman
Date: 08/25/2008
File Name: MC_PRG411_Final_WK2
Purpose: To calculate the amount a Mortgage Payement will be from
user input values.
*/
#include <iostream> // Library defines facilities for basic I/O operations...
#include <iomanip> // Libaray for stream manipulators...
#include <string> // Library for accepting stings...
#include <limits> // Library for setting limits...

using namespace std; // Standard using definitions...

class MortgageCal
{
private:
double intYear; // interest rate per year...
double intMonth; // interest converted to months...
double loanAmt; // amount of the loan...
double term; // term in years...
double numMonths; // term converted to months...
double paymentAmt; // variable for monthly payment...
double balance; // running total...
double principleAmt;// amount towards loan...
double amtMortgage; // total amount to be paid back...

public:

// Constructor, initializes any unpassed value to zero...
MortgageCal(
double intYear = 0,
double term = 0,
double loanAmt = 0,
double paymentAmt = 0,
double numMonths = 0,
double intMonth = 0,
double balance = 0,
double principleAmt = 0,
double amtMortgage = 0) :
intYear(intYear),
term(term),
loanAmt(loanAmt),
paymentAmt(paymentAmt),
numMonths(),
intMonth(),
balance(),
principleAmt(),
amtMortgage() { }


// get and set for data elements...
double getIntYear() { return intYear; }
bool setIntYear(double year) { intYear = year; return true; }
double getTermInMonths() { return intYear * 12; } // preform calculations...
bool setTermInMonths(double months)
{
if (months > 0) { intYear = months/12; }
else { return false; }
return true;
}
double getTermInYears() { return term; }
bool setTermInYears(double years)
{
if (years > 0) { term = years; }
else { return false; }
return true;
}
double getPrinciple() { return principleAmt;}
bool setPrinciple(double principle)
{
if (principle >= 0) { principleAmt = principle; }
else { return false; }
return true;
}
double getLoanAmount(){ return loanAmt; }
bool setLoanAmount(double loan)
{
if (loan >= 0) { loanAmt = loan; }
else { return false; }
return true;
}

double getPaymentAmount() { return paymentAmt; }
bool setYearlyRate(double rate)
{ intYear = rate;
return true;
}

//Declarations for other member functions...
void Amortization();
}; // end class

// function to get input from the user...
double getRangedInput(const string prompt, double min, double max, int tries = 5);
void pause(); //pause

//main() function. Controls the main logic needed to interface with the user...

int main()
{
double loanAmount; // Initialize original amount of loan...
double term; // Initialize term of loan in years...
double yearlyRate; // Initialize interest rate of loan...

MortgageCal morgCalc; // Redefine class as subclass...
char indicator = 'y'; // set indicator to 'y' for continue...
while ((indicator =='y') || (indicator == 'Y')) // to continue loop as long as input = y
{
/*get and set all of the input from the user/ranges...
Set up screen output to display mortgage amount, interest
rate and term of loan...*/
loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
cout << endl;
term = getRangedInput("Please enter the loan term in years", 0, 10000);
cout << endl;
yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
cout << endl;
morgCalc.setLoanAmount(loanAmount);
morgCalc.setTermInYears(term);
morgCalc.setYearlyRate(yearlyRate);

//display the payment calculations...
morgCalc.Amortization();
{
cout << "After Amortinzation:\n"
<< endl
<< "Your payments will be: $" << morgCalc.getPaymentAmount() << endl
<< endl;


cout << endl
<< "This is a breakdown of "
<< "how much of your payment is applied " << endl;
cout << "to interest and the "
<< "balance of your loan: " << endl;
system ( "PAUSE" );
cout << endl << endl; // headings
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;

int intPymtNum = 1; // counter for payments
int max = 0; // displays maximum lines on screen
double intRate = 0.0; // calculated loan interest
double intPayment = 0.0; // interest amount applied to loan
double principleAmt = 0.0; // principle amount applied to loan
double loanBal = 0.0; // running balance of loan
loanBal = loanAmount; // used for running total*/

for(int i = 1, max = 1; intPymtNum <= numMonths; i++)
{ // controls the loop of monthly payments
intRate = intMonth; //intMonth;
intPayment = loanBal * intRate;
principleAmt = paymentAmt - (loanBal * intRate);
loanBal = loanBal - principleAmt;

if (loanBal <= 0)
{
loanBal = 0; // to avoid negative numbers
}
cout << endl
<< setw(5) << intPymtNum << setw(17)
<< intPayment << setw(15) << loanBal;
intPymtNum++; // adds 1 to payment number
max++; // adds 1 to line count */

if (max == 20)
{ // loop pauses program every 20 lines
cout << endl;
system ( "PAUSE" );
//max = 1; // resets line count
cout << endl << endl; // prints headings again
cout << " Payment" << setw(15) << "Interest"
<< endl;
cout << " Number " << setw(15) << " Paid "
<< setw(14) << "balance " << endl;
cout << " _______" << setw(15) << "________"
<< setw(14) << "________" << endl;
} // end if loop
} // end for loop
} // end Print_List()

pause(); // to get user input to enter new values...
cout << endl; // Enter newline...
//Set up screen for input on whether to enter new numbers or exit...
cout << "Do you want to enter another value (enter y to continue or n to end)? ";
cin >> indicator; // Read indicator input...
cout << endl;
} // end while

cout << endl;
cout << "\"Thank you for using our mortgage calculator\"" << endl;
cout << endl;
return 0; // End program...
}

/**
*Function for getting input from the user.
* If the user enters an invalid string, or if the user enters a value outside of the
* given range then it will give the user an error message...
*/
double getRangedInput(const string prompt, double min, double max, int tries)
{
int userTry = 0;
double userInVal = 0;
bool isValidInput;
do {
cout << prompt << ": ";
cin >> userInVal;
if (!cin.good())
{
cout <<endl;
cout << "INPUT ERROR: Please input a proper number!" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
isValidInput = false;
} else
{
isValidInput = (userInVal >= min && userInVal <= max);
}
if (!isValidInput)
{
cout << "Please enter a value between " << min << " and " << max << "!" << endl;
cout << endl;
}
} while (!isValidInput && ++userTry < tries); // end while...
if (userTry == tries)
{
cout << "User input invalid, can not process!" << endl;
exit(1); //If the user can't input a valid value, exit the program...
}
return userInVal;

} // end of get for error input...

void pause()
{
cout << "Press enter to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.ignore();
}

/*define member functions...
Determines monthly interest in decimal format
Set up monthly payment calculations...*/

void MortgageCal::Amortization()
{
numMonths = term * 12; // Converts years to months...
intMonth = intYear/1200; // Converts annual rate to monthly rate...
paymentAmt = (loanAmt*intMonth)/(1-pow(1+intMonth,-numMonths)); // Amortization formula...

}

[code]
I may have parts of this in the wrong place but it just doesn't make sense to me.
Thanks a million Nick and like I said I sure wish that you where my instructor.
Ken
Thanks a million Nick and like I said I wish that you where my instructor.

Nick,
I forgot to ment tion the 3 indentifiers are:
numMonths, intMonth and paymentAmt.
Ken

Thanks Nick for all, I will see if I can figure it out. I don't know why but this is sure tough for me. I did good in Java and just C++, but tryng to go to OOP in C++ there is just something that isn't clicking.
Thanks,
Ken

Nick,
I just wanted to let you know, thanks to your help, I got this part of the program to run as well. Now on to the next part.
Ken
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2