LNK1102 and LNK2001 errors

When I try to run the code below, I get the errors LNK2001 and LNK1102. I am a newb to C++ so maybe I am missing something really basic?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>

using namespace std;

class Order // Class order and its attributes
{
public:
        void setName(string myName);
        string getName();
        void setNumber(int ID);
        int getNumber();
        void setQuanity(int Quant);
        int getQuanity();
        void setPrice(double money);
        double getPrice();
        double calculateTotalPrice();
        void printOrder();
        double ship;
        void SetShip(int yes);
private:
        string name;
        int number;
        int quantity;
        double price;
        double total;
};


class ShippedOrder: public Order //Subclass of ShippedOrder
{
public:
        void SetShip(int yes);
private:
        double shipping;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  #include"Order.h"
#include<iostream>
#include<string>

using namespace std;

string Order::getName()
{
        return name;
}
int Order::getNumber()
{
        return number;
}
double Order::getPrice()
{
        return price;
}
int Order::getQuanity()
{
        return quantity;
}
double Order::calculateTotalPrice()
{
        return price * quantity + ship;
}
void Order::setName(string myName)
{
        myName = name;
}
void Order::setNumber(int ID)
{
        ID = number;
}
void Order::setQuanity(int Quant)
{
        Quant = quantity;
}
void Order::setPrice(double money)
{
        money = price;
}

void Order::SetShip(int yes)
{
        cin >> yes;
        switch (yes)
        {
                case 'y':
                        Order.ship = 4.00;
                        break;
                case 'n':
                        Order.ship = 0.00;
						break;
                default:
                        cout<< "please enter a (y) or (n)"<<endl;
        }
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<string>
#include"Order.h"

using namespace std;

int main()
{
	 string yourName;
        int yourNumber;
        int yourQuantity;
        double yourPrice;
        int Yes;

        Order newOrder;
        
        cout<< "Enter your First and last name: "<<endl;
        cin>> yourName;
        newOrder.setName(yourName);
        cout<< "Enter your member ID number: "<<endl;
        cin>> yourNumber;
        newOrder.setNumber(yourNumber);
        cout<< "Enter the quantity bought: "<<endl;
        cin>> yourQuantity;
        newOrder.setQuanity(yourQuantity);
        cout<< "Enter the price per unit: "<<endl;
        cin>> yourPrice;
        newOrder.setPrice(yourPrice);
        cout<< "Thank you! Your name is: " << yourName
                << "\nYour ID number is: "<< yourNumber
                << "\nThe amount purchased is: " <<yourQuantity
                << "\nThe price per unit is: " << yourPrice
                << "\nThe total amount due before shipping is: "<< yourQuantity * yourPrice<<endl;
        system("CLS");
        cout<< " Would you like to ship this product? "<<endl;
        cin >> Yes;
        newOrder.SetShip(Yes);        


	    system("pause");

        return 0;
}
Post the error messages, not just the error codes. People don't generally memorize compiler error codes.
Here are the error codes:

1>------ Build started: Project: M8A1, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\Kevin Mix\Documents\Visual Studio 2010\Projects\M8A1\Debug\M8A1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sounds like you forgot to add the file that contains main() to the project.
closed account (E0p9LyTq)
Those errors mean VS was unable to find a main function.

I used VS2015 Community, created an empty project and added your code. After killing several nasty bugs in your Order.cpp file I was able to successfully compile the code.

The bugs were in your setter and SetShip methods. Here is what I changed them to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void Order::setName(string myName)
{
   name = myName;
}
void Order::setNumber(int ID)
{
   number = ID;
}
void Order::setQuanity(int Quant)
{
   quantity = Quant;
}
void Order::setPrice(double money)
{
   price = money;
}

void Order::SetShip(int yes)
{
   cin >> yes;
   switch (yes)
   {
      case 'y':
         Order::ship = 4.00;
         break;
      case 'n':
         Order::ship = 0.00;
         break;
      default:
         cout<< "please enter a (y) or (n)"<<endl;
   }
}
@helios

Thanks for that. I knew it had to be something pretty basic.
closed account (E0p9LyTq)
Your SetShip method could be rewritten as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Order::SetShip(int yes)
{
   cin >> yes;
   switch (yes)
   {
      case 'y':
         ship = 4.00;
         break;
      case 'n':
         ship = 0.00;
         break;
      default:
         cout<< "please enter a (y) or (n)"<<endl;
   }
}


Why are you using a function parameter when you ignore the value, asking for a new value in the function?
Remember to put include guards around your .h/.hpp file contents

Order.h
1
2
3
4
5
6
#ifndef ORDER_H
#define ORDER_H

class Order;

#endif //ORDER_H 


also if you include something in the .h/.hpp file, you don't have to include it again in your .cpp!

Order.cpp file
1
2
3
4
5
6
7
8
9
10
11
#include "Order.h"

//no need for #include <iostream> here

using namespace std;

string Order::getName(){
        return name;
}

//...etc... 
Last edited on
Topic archived. No new replies allowed.