undefined reference

Thank you for the people who answered my first question about this damn program.
I'm getting these errors now

/tmp/ccwUdKkK.o: In function `main':
mailOrder.cpp:(.text+0x3b): undefined reference to `getCustomerInfo(int, int, int, int, int)'
mailOrder.cpp:(.text+0x17d): undefined reference to `outputInvoice(int, std::string, int, int, int, float, float, float, float)'
collect2: error: ld returned 1 exit status

No idea how to solve that.



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 #include<iostream>
#include <iomanip>
using namespace std;
//prototypes
void getCustomerInfo (int accountNum, int saleMonth, int saleDate, int saleYear, int countyCode);
void getItemInfo (float totalPrice, int totalWeight);
float calcDiscount (float price, int saleMonth);
int calcSalesTax (double price, char countyCode);
float calcShipping (int weight);
void outputInvoice (int accountNum, string county, int saleMonth, int saleDate, int saleYear, float price, float discount, float tax, float shipping);


int main()
{
  char countyCode;
  int saleMonth,saleDate, saleYear, accountNum, weight=0;
  float price;

  float totalPrice;
  float totalWeight;

  //what I'm getting from customers
  getCustomerInfo(accountNum, saleMonth, saleDate, saleYear, countyCode);
  getItemInfo (totalPrice,totalWeight);
  //what I am calculating
  float  discount = calcDiscount (price, saleMonth);
  float tax = calcSalesTax (price - discount, countyCode);
  float shipping = calcShipping (weight);


  string county;
  if (countyCode == 'S')
  {
county = "San Diego";
  }
  else if (countyCode == 'L')
  {
    county = "Los Angeles";
  }
  else if (countyCode == 'O')
  {
    county = "Orange";
  }

  outputInvoice (accountNum, county, saleMonth, saleDate, saleYear, price, discount, tax, shipping);

  return 0;
}





void  getCustomerInfo (int accountNum, int saleMonth,int saleDate, int saleYear, char countyCode)
{
  cout << "Enter account number: ";
  cin >> accountNum;
  cout << "Date of sale (x/xx/xxxx): ";
  cin >> saleMonth >> saleDate >> saleYear;
  cout << "Enter the county code: ";
  cin >> countyCode;
}

void getItemInfo (float totalPrice, int totalWeight)
{
  char choice;
  int weight;
  float price;
  totalPrice = 0;
  totalWeight = 0;
  cout << "\nDo you want to order an item? Enter Y or N: ";
  cin >> choice;

  while (choice == 'Y')
    {
      cout << "Enter a price: ";
      cin >> price;
      cout << "Enter a weight: ";
      cin >> weight;
      totalPrice += price;
      totalWeight += weight;
      cout << "Do you want to order another item? Enter Y or N: ";
      cin >> choice;
    }
}
float calcDiscount (float price, int saleMonth)
{
  if (saleMonth >= 1 && saleMonth <= 5)
    return price * 5/100;
  if (saleMonth >= 6 && saleMonth <= 8)
    return price * 10/100;
  else
    return price * 15/100;
}

int calcSalesTax (double price, char countyCode)
{
  if (countyCode == 'C')
    {
      return price * 7.75/100;
    }
  else if (countyCode == 'O')
    {
      return price * 7.75/100;
    }
  else if (countyCode == 'L')
    {
      return price * 8.85/100;
    }
}

float calcShipping (int weight)
{
 if (weight <= 25)
    return 5.00;
  else if (weight <= 50)
    {
      float shipping = 5;
      shipping += (weight * 1.0-25) * 10/100;
      return shipping;
     }
   else if (weight >= 50)
     {
       float shipping = 7.5;
       shipping += (weight *1.0-50)* 7/100;
       return shipping;
     }
}

void outputInvoice (int accountNum, char county, int saleMonth, int saleDate, int saleYear, float price, float discount, float tax, float shipping)
{
  cout << "ACCOUNT NUMBER" << setw(20)<< "COUNTY"<< endl;
  cout << accountNum << setw(30) << county << endl;
  cout << "DATE OF SALE " << saleMonth << "/" << saleDate << "/" << saleYear << endl;
  cout << setw(30) << std::left << "TOTAL SALE AMOUNT: " << "$" << price << endl;
  cout << setw(30) << std::left << "DISCOUNT: " << "$ " << discount << endl;
  cout << setw(30) << std::left <<"SALES TAX: " << "$ " << tax << endl;
  cout << setw(30) << std::left << "SHIPPING: " << "$ " << shipping << endl;
  cout << setw(30) << std::left << "TOTAL DUE: "<< "$ " << price+tax+shipping-discount<<endl;
}

Last edited on
On line 10/11 you provided the prototypes of your get... functions. So you need to provide the prototypes of your calc... functions as well before you can actually use them.
I'd guess the intention at lines 10/11 was to actually call the functions getCustomerInfo
and getItemInfo. The prototype declarations just there appear to be a mistake.

Usually, the program would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
#include headers

// declare prototypes

int main()
{

    // call the functions as required

}

// define the entire functions here 


There's an example under the heading Declaring functions
near to the bottom of the tutorial page:
http://www.cplusplus.com/doc/tutorial/functions/

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
#include<iostream>
#include <iomanip>
using namespace std;

// add these forward declarations here
void getCustomerInfo(int, int, int, int, char);
void getItemInfo(float, int);
float calcDiscount(float, int);
int calcSalesTax(double, char);
float calcShipping(int);
// forward declarations should be before any functions and outside any 

int main()
{
    // stuff...
}

void  getCustomerInfo (int accountNum, int saleMonth, int saleDate, int saleYear, char countyCode)
{
    // stuff...
}

void getItemInfo (float totalPrice, int totalWeight)
{
    // stuff...
}

float calcDiscount (float price, int saleMonth)
{
    // stuff...
}

int calcSalesTax (double price, char countyCode)
{
    // stuff...
}

float calcShipping (int weight)
{
    // stuff...
}
Last edited on
The function calls to
1
2
  getCustomerInfo (accountNum, saleMonth, saleDate, saleYear, countyCode);
  getItemInfo (price, weight);

need to be inserted in main().

Also, Since those two functions are supossed to get the information and return it to the caller, the parameters need to be passed by reference.
The prototype and function header both need to look like this:
 
void getItemInfo (float &totalPrice, int &totalWeight)
Note the ampersand & because the parameters are passed by reference.

See the same tutorial page again for explanations:
http://www.cplusplus.com/doc/tutorial/functions/

In general, I'd recommend keeping the names of the parameters in the prototypes,

 
void  getCustomerInfo (int &accountNum, int &saleMonth, int &saleDate, int &saleYear, char &countyCode);
is much more meaningful than
 
void  getCustomerInfo (int &, int &, int &, int &, char &);
It makes the code to some extent self-documenting and lets the user of the function know how to use the function.
Please do not modify your original post so that the answers don't make sense.

I'm getting these errors now
Your problem is that the [signature of the] prototype and the implementation of those functions don't match.

what I'm getting from customers
You don't get anything. See Chervil's post:
http://www.cplusplus.com/forum/beginner/201002/#msg958713
Topic archived. No new replies allowed.