Thread: LNK2019 error

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    6

    LNK2019 error

    Assignment:
    Design a class to store measurements. The class should have two data items, feet and inches, both integers. The class must make sure that the number of inches never gets below zero or above 11. If inches is outside that range, adjust feet accordingly. (Yes this means feet might be a negative number.)

    Create a default constructor and one which receives one integer, a number of inches.

    Overload the following operators: addition, subtraction, equality, inequality, incrementation (both pre and post) (should add one to inches), and output (in the form of: F’I”)
    Code:
    #include <iostream>
    
    using namespace std;
    
    
    class measurements {
    
    
    private:
    	int inches;
    	double feet;
    
    
    public:
    	int GetInches() {return inches;}
    	double GetFeet() {return feet;}
    	measurements();
    	measurements(int,double);
    	measurements operator+(const measurements& value);
    	measurements operator-(const measurements& value);
    	measurements& operator++(); //pre
    	measurements operator++(int); //post
    	friend bool operator==(const measurements& lhs, const measurements& rhs);
    	friend bool operator!=(const measurements& lhs, const measurements& rhs);
    	friend ostream& operator<< (ostream &out, const measurements& value);
    };
    
    
    measurements::measurements(){
    	inches = 1;
    	feet = 1;
    }
    
    
    measurements::measurements(int inchs, double ft){
    	inches = inchs;
    	feet = ft;
    }
    
    
     ostream &operator<< (ostream& out, const measurements& value)
    {
      
        out << "F:" <<value.feet << "'";
        out << "I:" <<value.inches << " \" ";
        return out;
    }
    
    
     double Normalize(double feet, int inches){
    	 if(inches == 0 || inches < 0){
    	 cout<< "Enter a number bigger than zero!"<< endl;
    	 }
    	 else{
    		 while(inches > 11){
    		 inches = inches - 12;
    		 ++feet;
    		 return feet;
    		 }
    		 if((inches > 0) & (inches < 12)){
    			 feet = inches % 12;
    			 return feet;
    			}
    	 }
     }
    
    
    bool operator==(const measurements& lhs, const measurements& rhs)
    {
    	return(lhs.inches == rhs.inches && lhs.feet == rhs.feet);
    }
    
    
    bool operator!=(const measurements& lhs, const measurements& rhs)
    {
    	return(lhs.inches != rhs.inches) || (lhs.feet != rhs.feet);
    }
    
    
    measurements& measurements::operator++(){
    	inches++;
    	return *this;
    	}
    
    
    measurements measurements::operator++(int){
    	measurements temp;
    	temp.inches = inches;
    	inches++;
    	return temp;
    	}
    
    
    
    
    measurements measurements::operator+(const measurements& value)
    {
    	measurements temp;
    	temp.inches = value.inches + value.inches;
    	return temp;
    	
    }
    
    
    measurements measurements::operator-(const measurements& value)
    {
    	measurements temp;
    	temp.inches = value.inches - value.inches;
    	return temp;
    	
    }
    
    
    int main(){
    	int inches;
    	double feet = 0;
    	cout<<"Enter an integer number of inches: ";
    	cin>> inches;
    	measurements Msrmnt1(inches, feet);
    	feet = Normalize(feet,inches);
    	cout<<"The amount of feet is: "<<feet<<endl;
    }
    Im getting a LNK2019 error and an LNK1120 errors:

    Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    Error 2 error LNK1120: 1 unresolved externals
    I have no idea what is causing them. Any insight/help would be greatly appreciated!
    Last edited by pochta; 07-08-2013 at 06:17 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Every C++ program must have a main() function. Where is your's?

    Jim

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    Ok now its there. I edited the first post. The errors are gone but it's not working the way it should be. Namely the "Normalize" function is not working the way I intended it to. It keeps giving me back 1 foot regardless of the number of inches.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Also posted here.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error LNK2019
    By Mycroft Holmes in forum C++ Programming
    Replies: 9
    Last Post: 04-17-2013, 07:17 AM
  2. Replies: 7
    Last Post: 10-27-2012, 02:55 PM
  3. Help on error LNK2019
    By jlbfunes in forum C++ Programming
    Replies: 5
    Last Post: 08-21-2008, 08:19 AM
  4. I got error LNK2019
    By Daggio in forum Windows Programming
    Replies: 3
    Last Post: 03-14-2008, 02:29 AM
  5. Main.obj : error LNK2019:
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-18-2007, 05:39 AM