LNK2019: unresolved external

Error in compiler

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 tyserman474  Icon User is offline

  • D.I.C Head

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

LNK2019: unresolved external

Post icon  Posted 23 August 2008 - 04:09 PM

Hi Everyone,
I am really having some problems yet, I keep getting this error:

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib
Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\Ken\Documents\Visual Studio 2005\Projects\MC_PRG411_WK2_2\Debug\MC_PRG411_WK2_2.exe 1

I have searched all over the place and can't seem to get an answer that works for me. I think that my program will work if I can get this taken care of. I have been working on this for several days now.

My class is called:
mortgageCal
then under the end of my class file I have;

mortgageCal::mortgageCal()
{
intYear = 0;
term = 0;
loanAmt = 0;
paymentAmt = 0;
}



Now I was under the impression that the above statement would link, or what ever you call it, the class file with the rest of the program but I guess that it doesn't. All of these items are in the class file as well.
Can anyone please give me help on how to solve this please?
Thanks

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: LNK2019: unresolved external

#2 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 23 August 2008 - 04:29 PM

Ok, the file compiles fine, and produces and obj file... THEN you try to make an .ext with it which can't happen because it does not define an entry point. (_main)

So... what to do... well really you want to add the file to your project and compile at with your project. Make sure that VC++ knows which file is the main program.
Was This Post Helpful? 0
  • +
  • -

#3 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 23 August 2008 - 09:19 PM

View PostNickDMax, on 23 Aug, 2008 - 04:29 PM, said:

Ok, the file compiles fine, and produces and obj file... THEN you try to make an .ext with it which can't happen because it does not define an entry point. (_main)

So... what to do... well really you want to add the file to your project and compile at with your project. Make sure that VC++ knows which file is the main program.


Nick,
Thank you very much, that did work!
Now I have a new problem, it seems like know matter what I try it doesn't work good for me. When I run the following program I get these errors and can't find them.
Error 1 error C2612: trailing 'type' illegal in base/member initializer list c:\users\ken\documents\visual studio 2005\projects\mc_wk2_try3\mc_wk2_try3\mc_wk@_try3.cpp 57
Error 2 error C2601: 'main' : local function definitions are illegal c:\users\ken\documents\visual studio 2005\projects\mc_wk2_try3\mc_wk2_try3\mc_wk@_try3.cpp 58
Error 3 fatal error C1004: unexpected end-of-file found c:\users\ken\documents\visual studio 2005\projects\mc_wk2_try3\mc_wk2_try3\mc_wk@_try3.cpp 151
// MC_PRG_V6.cpp : main project file.

  
	#include <iostream>  
	#include <iomanip>  
	#include <math.h>  
	#include <stdlib.h>  
	#include<cctype>        // Functions verification

	using std::cin;  
	using std::cout;  
	using std::endl;  
	using std::fixed;
	using std::setprecision;  
	using std::setw;  
	using namespace std;
	 
	class mortgageCal  
	{  
	    private:  
	        double intYear;         // interest rate per year  
	    public:
			mortgageCal();
	mortgageCal(double intYear, double term, double loanAmt, double paymentAmt,
	double numMonths, double intMonth, double balance, double principleAmt,
	double amtMortgage);
	        double loanAmt;       // amount of the loan  
	        double term;        // term in years  
	        double numMonths;     // term converted to months  
	        double intMonth;      // interest 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
			double Get_Input(void)
			{
			return 0;
			}
			

	};
	
	mortgageCal::mortgageCal(double intYear, double loanAmt, double term,
		double numMonths, double intMonth, double paymentAmt,
		double balance, double principleAmt, double amtMortgage):
					
intYear(0)
, loanAmt(0)
, term(0)
, numMonths(0)
, intMonth(0)
, paymentAmt(0)
, balance(0)
, principleAmt(0)
, amtMortgage(0)
					
	 int main()
	 {
		void Get_Input()  

		{
	        while (1)
			//system("cls");
			{
				// clears the screen
			system("cls");
	        cout << "Please enter a loan amount." << endl;  
	        cin  >> loanAmt;  
	        cout << endl; 
	
			if (cin.fail()) // no extraction took place
			{
			cout << "Please input a valid number" << endl;
			system("pause");
            cin.clear(); // reset the state bits back to goodbit so we can use ignore()
            cin.ignore(1000, '\n'); // clear out the bad input from the stream    
			continue; // try again
			}
	         
	        cout << "Please enter the loan term in years." << endl;  
	        cin  >> term;  
	        cout << endl;

			if (cin.fail()) // no extraction took place
			{
			cout << "Please input a valid number" << endl;
			system("pause");
            cin.clear(); // reset the state bits back to goodbit so we can use ignore()
            cin.ignore(1000, '\n'); // clear out the bad input from the stream
			continue; // try again
			}
			
	        cout << "Please enter interest rate." << endl  
	             << "The amount must be in decimal format:" << endl;  
	        cin  >> intYear;  
	        cout << endl;
			if (cin.fail()) // no extraction took place
			{
			cout << "Please input a valid number" << endl;
			system("pause");
            cin.clear(); // reset the state bits back to goodbit so we can use ignore()
            cin.ignore(1000, '\n'); // clear out the bad input from the stream
			continue; // try again
			}
			else
			{
				break;
			}	
			
			} // end while
	       
		} // end get
	
	    //void 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  
			} // end Amortization()  
	  
	    //void Print_Output()  
			{  
	        cout << endl
	             << "Based on your input..." << endl  
	             << "Your Monthly Mortgage Payment Amount will be: $ "  
	             << fixed << setprecision(2)    // Displays amount to two decimal places  
	             << paymentAmt << endl;	// Displays the monthly payment 
					system("pause");
			} // end Print_Output()  
			 
	    mortgageCal mortCalc;     // an object of the class mortgageCal  
	  
	    char chIndicator = 'q'; // to quit or continue  
	  
	    do{  
	        mortCalc.Get_Input();  
	        if (!cin)       // if any input from Get_Input() function is    
	            return 0;   // invalid it will terminate the program
	        cout << endl;         // Next line  
	        cout << "Press 'q' to quit or any key to start over: ";  
	        cin  >> chIndicator;  // Reads input from user  
	        cout << endl;  
	  
	      }while ((chIndicator !='q') && (chIndicator != 'Q')); // end do loop  
	 
	    return 0;  
	} // end main() 



Can you tell me what is wrong please?
Thanks

** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#4 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 23 August 2008 - 10:38 PM

well just off the top of my head: look at lines 43-55. This constructor needs to look more like this (just an example):

foo::foo() : bar(0) { }

note the backets at the end.

you defined a function void Get_input() INSIDE of main()!

All in all I would say that this program is a mess... you need to break it down to the simplest form and copy small code bocks in and re-assemble it.

Start with just main() and build up.
Was This Post Helpful? 0
  • +
  • -

#5 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 24 August 2008 - 08:02 AM

View PostNickDMax, on 23 Aug, 2008 - 10:38 PM, said:

well just off the top of my head: look at lines 43-55. This constructor needs to look more like this (just an example):

foo::foo() : bar(0) { }

note the backets at the end.

you defined a function void Get_input() INSIDE of main()!

All in all I would say that this program is a mess... you need to break it down to the simplest form and copy small code bocks in and re-assemble it.

Start with just main() and build up.

Nick,
Thank you again for your input. What does the "il" in the brackets mean that you added? When I put that in I get all kinds of errors. I put the {} in and then took out the Get_Input and then I get "undeclared indentifer" for my objects, no other errors. Trying to learn this isn't that easy I guess. I will keep trying but I have to have this done today too, figures huh! I had the program running but the instructor want me to make the "class" separate from the rest and I ended up with all these problems.
Thanks Again Nick
Was This Post Helpful? 0
  • +
  • -

#6 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 24 August 2008 - 08:26 AM

...the "il" in brackets is part of the forum's BBCode... It stands for 'inline' and is used to make the pretty little box display around that line of code.

the foo-bar example was not meant for you to copy and paste -- it would have no meaning in your program. I meant to illustrate the format that a constructor using the nice initializer list would look like.

If I had a class named foo, and it had an internal value bar that I wanted to initialize to zero upon creation of the class then this is the format it would take (do NOT copy and paste into your code):
class foo {
private:
	int bar;
public:
	foo() : bar(0) { } //the constructor is a function and MUST have a body... thus the { }'s
}; //note the; and the end of a class definition!

This post has been edited by NickDMax: 24 August 2008 - 08:27 AM

Was This Post Helpful? 0
  • +
  • -

#7 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 24 August 2008 - 10:25 AM

View PostNickDMax, on 24 Aug, 2008 - 08:26 AM, said:

...the "il" in brackets is part of the forum's BBCode... It stands for 'inline' and is used to make the pretty little box display around that line of code.

the foo-bar example was not meant for you to copy and paste -- it would have no meaning in your program. I meant to illustrate the format that a constructor using the nice initializer list would look like.

If I had a class named foo, and it had an internal value bar that I wanted to initialize to zero upon creation of the class then this is the format it would take (do NOT copy and paste into your code):
class foo {
private:
	int bar;
public:
	foo() : bar(0) { } //the constructor is a function and MUST have a body... thus the { }'s
}; //note the; and the end of a class definition!


Nick,
for some reason the "il" in the 2 brackets aren't showing up now and I forgot where they where supposted to be, sorry. Can you send them again as to where they are supposed to be? I think that you had them at the very start after the class difinition, but not sure. Now all of the above goes into the class function, correct?
Thanks again, you are a very big help!!!
Was This Post Helpful? 0
  • +
  • -

#8 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 24 August 2008 - 10:53 AM

View Posttyserman474, on 24 Aug, 2008 - 10:25 AM, said:

View PostNickDMax, on 24 Aug, 2008 - 08:26 AM, said:

...the "il" in brackets is part of the forum's BBCode... It stands for 'inline' and is used to make the pretty little box display around that line of code.

the foo-bar example was not meant for you to copy and paste -- it would have no meaning in your program. I meant to illustrate the format that a constructor using the nice initializer list would look like.

If I had a class named foo, and it had an internal value bar that I wanted to initialize to zero upon creation of the class then this is the format it would take (do NOT copy and paste into your code):
class foo {
private:
	int bar;
public:
	foo() : bar(0) { } //the constructor is a function and MUST have a body... thus the { }'s
}; //note the; and the end of a class definition!


Nick,
for some reason the "il" in the 2 brackets aren't showing up now and I forgot where they where supposted to be, sorry. Can you send them again as to where they are supposed to be? I think that you had them at the very start after the class difinition, but not sure. Now all of the above goes into the class function, correct?
Thanks again, you are a very big help!!!

Nick, me again,
I put the inline brackets at the beginning of my code, right after the class definition and
having them there I get an error that;
error C2337: 'il' : attribute not found
I haven't tried the rest of your code but will right now.
I would like to send you something for all you have done for me, how can I do that? If it is legal that is.
Thanks
Was This Post Helpful? 0
  • +
  • -

#9 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 24 August 2008 - 12:35 PM

...I have to say that I am a little exasperated...

[il] is NOT C++ it is BBCode used by Dream.In.Code. DO NOT PUT IT INTO YOUR CODE! it has no meaning in C++!!!

DO NOT PASTE ANY OF THE CODE I HAVE PROVIDED IN THIS THREAD INTO YOUR PROGRAM!!!

The examples I gave are EXAMPLES of the syntax you need to use. They WILL NOT work in your program as is.
Was This Post Helpful? 0
  • +
  • -

#10 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 24 August 2008 - 04:29 PM

ok... one time deal.

The following code IS NOT COMPLETE. but it will get you started if you are careful. It will compile and will run, but it is incomplete. It is mean to get your started ONLY!

Please look over the code and try to finish it up. You well need to:
1. Add the rest of the getters and setters.
2. Write a proper output routine
3. implement whatever else your assignment askes for

// MC_PRG_V6.cpp : main project file.
#include <iostream>  
#include <iomanip>
#include <string>
#include <limits>
#include <cmath>  
#include <cstdlib>  
#include <cctype>        
using namespace std;
	 
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:

		//The Constructor, will initialize 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() { }
		
		//It is good to have "getters and setters" for your data elements.
		double getIntYear() { return intYear; }
		bool setIntYear(double year) { intYear = year; return true; }
		double getTermInMonths() { return intYear * 12; } // you can even 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; }
	
		//Note that I took Get_Input out of the class -- this is a user input and has nothing
		//  to do with the logic of the MortgageCal and therefore should not be part of that class


		//Declare other member functions to be defined later...
		void Amortization();
};

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

//Here is the main() function. It controls the main logic needed to interface with the user.
//  It should not contain "business logic" as this should be handeled by the MortgageCal class.
//  At the same time, MortgageCal class SHOULD NOT implement any user interface functions, as it is
//  a business logic class NOT a user interface class.
int main() {
	double loanAmount;
	double term;
	double yearlyRate;
	MortgageCal morgCalc;
	
	//Here we can get all of the input from the user...
	loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
	term = getRangedInput("Please enter the loan term in years", 0, 10000);
	yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
	morgCalc.setLoanAmount(loanAmount);
	morgCalc.setTermInYears(term);
	morgCalc.setYearlyRate(yearlyRate);
	
	
	//do the calculations
	morgCalc.Amortization();
	cout << "After Amortinzation:\n"
	     << "Payments: " << morgCalc.getPaymentAmount()
		 << endl;
	
	

	pause();
	return 0;
}

/**
 *Useful function for getting input from the user. It will prompt the user for an input,
 * 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 and error message. This will only allow the user
 * a cenrtain number of tries. The default number of tries is 5.
 * @param prompt - a prompt to display for the user.
 * @param min - the minimum value a user can enter.
 * @param max - the maximum value a user can enter.
 * @param tries - (optional) the maximum number of tries a user has to get a valid input.
 * @return -- the valid value the user has entered.
 */
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 << "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;
		}
	} while (!isValidInput && ++userTry < tries);
	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...
		//throwing an exception would actually be the better way to do this.
	}
	return userInVal;

}

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

//Down here we can define member functions that are too big to define inline...


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
}


WARNING: This code is incomplete.
Was This Post Helpful? 0
  • +
  • -

#11 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 24 August 2008 - 06:18 PM

View PostNickDMax, on 24 Aug, 2008 - 04:29 PM, said:

ok... one time deal.

The following code IS NOT COMPLETE. but it will get you started if you are careful. It will compile and will run, but it is incomplete. It is mean to get your started ONLY!

Please look over the code and try to finish it up. You well need to:
1. Add the rest of the getters and setters.
2. Write a proper output routine
3. implement whatever else your assignment askes for

// MC_PRG_V6.cpp : main project file.
#include <iostream>  
#include <iomanip>
#include <string>
#include <limits>
#include <cmath>  
#include <cstdlib>  
#include <cctype>        
using namespace std;
	 
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:

		//The Constructor, will initialize 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() { }
		
		//It is good to have "getters and setters" for your data elements.
		double getIntYear() { return intYear; }
		bool setIntYear(double year) { intYear = year; return true; }
		double getTermInMonths() { return intYear * 12; } // you can even 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; }
	
		//Note that I took Get_Input out of the class -- this is a user input and has nothing
		//  to do with the logic of the MortgageCal and therefore should not be part of that class


		//Declare other member functions to be defined later...
		void Amortization();
};

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

//Here is the main() function. It controls the main logic needed to interface with the user.
//  It should not contain "business logic" as this should be handeled by the MortgageCal class.
//  At the same time, MortgageCal class SHOULD NOT implement any user interface functions, as it is
//  a business logic class NOT a user interface class.
int main() {
	double loanAmount;
	double term;
	double yearlyRate;
	MortgageCal morgCalc;
	
	//Here we can get all of the input from the user...
	loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
	term = getRangedInput("Please enter the loan term in years", 0, 10000);
	yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
	morgCalc.setLoanAmount(loanAmount);
	morgCalc.setTermInYears(term);
	morgCalc.setYearlyRate(yearlyRate);
	
	
	//do the calculations
	morgCalc.Amortization();
	cout << "After Amortinzation:\n"
	     << "Payments: " << morgCalc.getPaymentAmount()
		 << endl;
	
	

	pause();
	return 0;
}

/**
 *Useful function for getting input from the user. It will prompt the user for an input,
 * 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 and error message. This will only allow the user
 * a cenrtain number of tries. The default number of tries is 5.
 * @param prompt - a prompt to display for the user.
 * @param min - the minimum value a user can enter.
 * @param max - the maximum value a user can enter.
 * @param tries - (optional) the maximum number of tries a user has to get a valid input.
 * @return -- the valid value the user has entered.
 */
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 << "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;
		}
	} while (!isValidInput && ++userTry < tries);
	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...
		//throwing an exception would actually be the better way to do this.
	}
	return userInVal;

}

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

//Down here we can define member functions that are too big to define inline...


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
}


WARNING: This code is incomplete.


Nick,
Thank you so very much, maybe someday I will be able to do something for you, and I mean that!
I will put the rest of the code in that is missing, I think that I can do that right. After I get it turned in I think I will try and separate them so I have a .h file. I do need one of them for later in this course, hopefully I can do that as well. I have been working for 12 hours a day for at least 5 days now trying to get this right, your great.
Thanks Again,
Ken
Was This Post Helpful? 0
  • +
  • -

#12 tyserman474  Icon User is offline

  • D.I.C Head

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

Re: LNK2019: unresolved external

Posted 24 August 2008 - 09:26 PM

View Posttyserman474, on 24 Aug, 2008 - 06:18 PM, said:

View PostNickDMax, on 24 Aug, 2008 - 04:29 PM, said:

ok... one time deal.

The following code IS NOT COMPLETE. but it will get you started if you are careful. It will compile and will run, but it is incomplete. It is mean to get your started ONLY!

Please look over the code and try to finish it up. You well need to:
1. Add the rest of the getters and setters.
2. Write a proper output routine
3. implement whatever else your assignment askes for

// MC_PRG_V6.cpp : main project file.
#include <iostream>  
#include <iomanip>
#include <string>
#include <limits>
#include <cmath>  
#include <cstdlib>  
#include <cctype>        
using namespace std;
	 
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:

		//The Constructor, will initialize 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() { }
		
		//It is good to have "getters and setters" for your data elements.
		double getIntYear() { return intYear; }
		bool setIntYear(double year) { intYear = year; return true; }
		double getTermInMonths() { return intYear * 12; } // you can even 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; }
	
		//Note that I took Get_Input out of the class -- this is a user input and has nothing
		//  to do with the logic of the MortgageCal and therefore should not be part of that class


		//Declare other member functions to be defined later...
		void Amortization();
};

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

//Here is the main() function. It controls the main logic needed to interface with the user.
//  It should not contain "business logic" as this should be handeled by the MortgageCal class.
//  At the same time, MortgageCal class SHOULD NOT implement any user interface functions, as it is
//  a business logic class NOT a user interface class.
int main() {
	double loanAmount;
	double term;
	double yearlyRate;
	MortgageCal morgCalc;
	
	//Here we can get all of the input from the user...
	loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
	term = getRangedInput("Please enter the loan term in years", 0, 10000);
	yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
	morgCalc.setLoanAmount(loanAmount);
	morgCalc.setTermInYears(term);
	morgCalc.setYearlyRate(yearlyRate);
	
	
	//do the calculations
	morgCalc.Amortization();
	cout << "After Amortinzation:\n"
	     << "Payments: " << morgCalc.getPaymentAmount()
		 << endl;
	
	

	pause();
	return 0;
}

/**
 *Useful function for getting input from the user. It will prompt the user for an input,
 * 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 and error message. This will only allow the user
 * a cenrtain number of tries. The default number of tries is 5.
 * @param prompt - a prompt to display for the user.
 * @param min - the minimum value a user can enter.
 * @param max - the maximum value a user can enter.
 * @param tries - (optional) the maximum number of tries a user has to get a valid input.
 * @return -- the valid value the user has entered.
 */
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 << "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;
		}
	} while (!isValidInput && ++userTry < tries);
	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...
		//throwing an exception would actually be the better way to do this.
	}
	return userInVal;

}

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

//Down here we can define member functions that are too big to define inline...


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
}


WARNING: This code is incomplete.


Nick,
Thank you so very much, maybe someday I will be able to do something for you, and I mean that!
I will put the rest of the code in that is missing, I think that I can do that right. After I get it turned in I think I will try and separate them so I have a .h file. I do need one of them for later in this course, hopefully I can do that as well. I have been working for 12 hours a day for at least 5 days now trying to get this right, your great.
Thanks Again,
Ken

Nick,
While everything is working good for this one. I also had to add so the user could loop back and enter new values if they wanted too.
[code]
pause();
char indicator = ('y', 'Y', 'n', 'N');
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

// Decision whether to continue or not
if ((indicator == 'y') || (indicator == 'Y'))
cout << endl;
goto MyLabel; // Alter the flow of exicution to MyLabel
// Decision whether to continue or not
if ((indicator == 'n') || (indicator == 'N'))
return 0;

[code]
Boy is it different then your code. I had to use a label to get it to go back, couldn't find another way that it would work and I had to get it done for tomorrow, but it works.
Thanks Again Nick,
Ken
Was This Post Helpful? 0
  • +
  • -

#13 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 24 August 2008 - 09:47 PM

Do not use goto... use a do-while loop.

What is "char indicator = ('y', 'Y', 'n', 'N');" supposed to do? What does it do? it creates a new char named "indicator" and assigns it the value 'N'. Not sure what value that is.
Was This Post Helpful? 0
  • +
  • -

#14 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 - 07:51 AM

View Posttyserman474, on 24 Aug, 2008 - 09:26 PM, said:

View Posttyserman474, on 24 Aug, 2008 - 06:18 PM, said:

View PostNickDMax, on 24 Aug, 2008 - 04:29 PM, said:

ok... one time deal.

The following code IS NOT COMPLETE. but it will get you started if you are careful. It will compile and will run, but it is incomplete. It is mean to get your started ONLY!

Please look over the code and try to finish it up. You well need to:
1. Add the rest of the getters and setters.
2. Write a proper output routine
3. implement whatever else your assignment askes for

// MC_PRG_V6.cpp : main project file.
#include <iostream>  
#include <iomanip>
#include <string>
#include <limits>
#include <cmath>  
#include <cstdlib>  
#include <cctype>        
using namespace std;
	 
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:

		//The Constructor, will initialize 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() { }
		
		//It is good to have "getters and setters" for your data elements.
		double getIntYear() { return intYear; }
		bool setIntYear(double year) { intYear = year; return true; }
		double getTermInMonths() { return intYear * 12; } // you can even 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; }
	
		//Note that I took Get_Input out of the class -- this is a user input and has nothing
		//  to do with the logic of the MortgageCal and therefore should not be part of that class


		//Declare other member functions to be defined later...
		void Amortization();
};

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

//Here is the main() function. It controls the main logic needed to interface with the user.
//  It should not contain "business logic" as this should be handeled by the MortgageCal class.
//  At the same time, MortgageCal class SHOULD NOT implement any user interface functions, as it is
//  a business logic class NOT a user interface class.
int main() {
	double loanAmount;
	double term;
	double yearlyRate;
	MortgageCal morgCalc;
	
	//Here we can get all of the input from the user...
	loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
	term = getRangedInput("Please enter the loan term in years", 0, 10000);
	yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
	morgCalc.setLoanAmount(loanAmount);
	morgCalc.setTermInYears(term);
	morgCalc.setYearlyRate(yearlyRate);
	
	
	//do the calculations
	morgCalc.Amortization();
	cout << "After Amortinzation:\n"
	     << "Payments: " << morgCalc.getPaymentAmount()
		 << endl;
	
	

	pause();
	return 0;
}

/**
 *Useful function for getting input from the user. It will prompt the user for an input,
 * 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 and error message. This will only allow the user
 * a cenrtain number of tries. The default number of tries is 5.
 * @param prompt - a prompt to display for the user.
 * @param min - the minimum value a user can enter.
 * @param max - the maximum value a user can enter.
 * @param tries - (optional) the maximum number of tries a user has to get a valid input.
 * @return -- the valid value the user has entered.
 */
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 << "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;
		}
	} while (!isValidInput && ++userTry < tries);
	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...
		//throwing an exception would actually be the better way to do this.
	}
	return userInVal;

}

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

//Down here we can define member functions that are too big to define inline...


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
}


WARNING: This code is incomplete.


Nick,
Thank you so very much, maybe someday I will be able to do something for you, and I mean that!
I will put the rest of the code in that is missing, I think that I can do that right. After I get it turned in I think I will try and separate them so I have a .h file. I do need one of them for later in this course, hopefully I can do that as well. I have been working for 12 hours a day for at least 5 days now trying to get this right, your great.
Thanks Again,
Ken

Nick,
While everything is working good for this one. I also had to add so the user could loop back and enter new values if they wanted too.
[code]
pause();
char indicator = ('y', 'Y', 'n', 'N');
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

// Decision whether to continue or not
if ((indicator == 'y') || (indicator == 'Y'))
cout << endl;
goto MyLabel; // Alter the flow of exicution to MyLabel
// Decision whether to continue or not
if ((indicator == 'n') || (indicator == 'N'))
return 0;

[code]
Boy is it different then your code. I had to use a label to get it to go back, couldn't find another way that it would work and I had to get it done for tomorrow, but it works.
Thanks Again Nick,
Ken

Well I thought that it worked, but when I enter a "n" to exit the program it just goes back and asks to enter another value rather then exiting.
Can anyone help please, I have to have this in right after lunch, please?
Thanks


View PostNickDMax, on 24 Aug, 2008 - 09:47 PM, said:

Do not use goto... use a do-while loop.

What is "char indicator = ('y', 'Y', 'n', 'N');" supposed to do? What does it do? it creates a new char named "indicator" and assigns it the value 'N'. Not sure what value that is.

Nick,
I need to be able to enter new values or exit. The 'y' will allow me to go back and enter new values and the 'n' will let me exit the program.
Was This Post Helpful? 0
  • +
  • -

#15 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 - 09:31 AM

View Posttyserman474, on 25 Aug, 2008 - 07:51 AM, said:

View Posttyserman474, on 24 Aug, 2008 - 09:26 PM, said:

View Posttyserman474, on 24 Aug, 2008 - 06:18 PM, said:

View PostNickDMax, on 24 Aug, 2008 - 04:29 PM, said:

ok... one time deal.

The following code IS NOT COMPLETE. but it will get you started if you are careful. It will compile and will run, but it is incomplete. It is mean to get your started ONLY!

Please look over the code and try to finish it up. You well need to:
1. Add the rest of the getters and setters.
2. Write a proper output routine
3. implement whatever else your assignment askes for

// MC_PRG_V6.cpp : main project file.
#include <iostream>  
#include <iomanip>
#include <string>
#include <limits>
#include <cmath>  
#include <cstdlib>  
#include <cctype>        
using namespace std;
	 
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:

		//The Constructor, will initialize 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() { }
		
		//It is good to have "getters and setters" for your data elements.
		double getIntYear() { return intYear; }
		bool setIntYear(double year) { intYear = year; return true; }
		double getTermInMonths() { return intYear * 12; } // you can even 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; }
	
		//Note that I took Get_Input out of the class -- this is a user input and has nothing
		//  to do with the logic of the MortgageCal and therefore should not be part of that class


		//Declare other member functions to be defined later...
		void Amortization();
};

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

//Here is the main() function. It controls the main logic needed to interface with the user.
//  It should not contain "business logic" as this should be handeled by the MortgageCal class.
//  At the same time, MortgageCal class SHOULD NOT implement any user interface functions, as it is
//  a business logic class NOT a user interface class.
int main() {
	double loanAmount;
	double term;
	double yearlyRate;
	MortgageCal morgCalc;
	
	//Here we can get all of the input from the user...
	loanAmount = getRangedInput("Please enter the loan amount", 0, numeric_limits<double>::max());
	term = getRangedInput("Please enter the loan term in years", 0, 10000);
	yearlyRate = getRangedInput("Please enter the yearly interest rate", 0, 100);
	morgCalc.setLoanAmount(loanAmount);
	morgCalc.setTermInYears(term);
	morgCalc.setYearlyRate(yearlyRate);
	
	
	//do the calculations
	morgCalc.Amortization();
	cout << "After Amortinzation:\n"
	     << "Payments: " << morgCalc.getPaymentAmount()
		 << endl;
	
	

	pause();
	return 0;
}

/**
 *Useful function for getting input from the user. It will prompt the user for an input,
 * 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 and error message. This will only allow the user
 * a cenrtain number of tries. The default number of tries is 5.
 * @param prompt - a prompt to display for the user.
 * @param min - the minimum value a user can enter.
 * @param max - the maximum value a user can enter.
 * @param tries - (optional) the maximum number of tries a user has to get a valid input.
 * @return -- the valid value the user has entered.
 */
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 << "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;
		}
	} while (!isValidInput && ++userTry < tries);
	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...
		//throwing an exception would actually be the better way to do this.
	}
	return userInVal;

}

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

//Down here we can define member functions that are too big to define inline...


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
}


WARNING: This code is incomplete.


Nick,
Thank you so very much, maybe someday I will be able to do something for you, and I mean that!
I will put the rest of the code in that is missing, I think that I can do that right. After I get it turned in I think I will try and separate them so I have a .h file. I do need one of them for later in this course, hopefully I can do that as well. I have been working for 12 hours a day for at least 5 days now trying to get this right, your great.
Thanks Again,
Ken

Nick,
While everything is working good for this one. I also had to add so the user could loop back and enter new values if they wanted too.
[code]
pause();
char indicator = ('y', 'Y', 'n', 'N');
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

// Decision whether to continue or not
if ((indicator == 'y') || (indicator == 'Y'))
cout << endl;
goto MyLabel; // Alter the flow of exicution to MyLabel
// Decision whether to continue or not
if ((indicator == 'n') || (indicator == 'N'))
return 0;

[code]
Boy is it different then your code. I had to use a label to get it to go back, couldn't find another way that it would work and I had to get it done for tomorrow, but it works.
Thanks Again Nick,
Ken

Well I thought that it worked, but when I enter a "n" to exit the program it just goes back and asks to enter another value rather then exiting.
Can anyone help please, I have to have this in right after lunch, please?
Thanks


View PostNickDMax, on 24 Aug, 2008 - 09:47 PM, said:

Do not use goto... use a do-while loop.

What is "char indicator = ('y', 'Y', 'n', 'N');" supposed to do? What does it do? it creates a new char named "indicator" and assigns it the value 'N'. Not sure what value that is.

Nick,
I need to be able to enter new values or exit. The 'y' will allow me to go back and enter new values and the 'n' will let me exit the program.


Nick,
Well I did get it to work, but I couldn't find a way to get read of the goto. I did change to a do-while and tried to use continue, but that didn't work, so not sure what to put there to get the program to return.
Here is my code;
[code]
pause();
char indicator = ('y', 'Y', 'n', 'N');
do
{
//char indicator = ('y', 'Y', 'n', 'N');
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

// Decision whether to continue or not
if ((indicator == 'y') || (indicator == 'Y'))
{
cout << endl;
goto MyLabel;
}

if((indicator == 'n') || (indicator == 'N'));
{

}

}while ((indicator !='n') && (indicator != 'N')); // end do loop

return 0;
[code]
I will have to fly with this if I have too, I will try and keep working on it.
Thanks Again for everything!!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2