c++ problem

Im stuck here with a problem i get the errors that says

Hw1a.cpp:(.text+0x41): undefined reference to `calcCommission(float)'
Hw1a.cpp:(.text+0x65): undefined reference to `calcPay(float)'
Hw1a.cpp:(.text+0x75): undefined reference to `displayPay()'
collect2: error: ld returned 1 exit status




this is the description of what I have to code and I have included my code below any help would be appreciated

Include these 3 functions:
getSalesAmt
-This function prompts the user to enter a monthly sales amount.
-The amount is read and assigned to a variable.
-The value is then returned to main()

calcCommission
-This function calculates the commission based on the sales amount.
-If a salesperson sells more than $50,000. per month, the commission is 2% of the sales amount.
-If the sales are between $25,000 and $50,000., then the commission is 1.5% of the sales amount.
-However, if the sales are less than $25,000., there is no commission.
-The value is returned to main().

calcPay
-This function calculates the total monthly pay for a salesperson.
-A salesperson gets a monthly salary of $2,500. plus a commission, if the person earned a commission.
-The value is returned to main().

displayPay
-This function displays the total monthly pay for a salesperson.
-Format the output to two decimal places, and with the amounts aligned as shown.













#include<iostream>
using namespace std;


float getSalesAmt(float sales);
float calcCommission(float commission);
float calcPay(float pay);
void displayPay();

int main()

{

float sales = 0;
sales = getSalesAmt(sales);
float commission = 0;
commission = calcCommission(commission);
float pay = 2500;
pay = calcPay(pay);
displayPay();
return 0;
}

float getSalesAmt(float sales)
{

cout << "Enter the monthly sales amount: ";
cin >> sales;
return sales;
}
float calcCommission(float sales, float commission)

{

if (sales > 50000)
commission = sales * 0.02;
else if (sales > 25000 && sales < 50000)
commission = sales * 0.015;
else
commission = 0;
return commission;
}

float calcPay(float pay, float commission)

{

float totalPay = 0;
totalPay = pay * commission;
return totalPay;
}

void displayPay(float sales, float commission, float pay, float totalPay)

{

cout << "Monthly Sales: $ " << sales;
cout << "Commission: $ " << commission;
cout << "Base Pay: $ " << pay;
cout << "Total Pay: $ " << totalPay;
}

First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Where do you implement these functions:
1
2
3
calcCommission(float)
calcPay(float)
displayPay()
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
// Im stuck here with a problem i get the errors that says
// Hw1a.cpp:(.text+0x41): undefined reference to `calcCommission(double)'
// Hw1a.cpp:(.text+0x65): undefined reference to `calcPay(double)'
// Hw1a.cpp:(.text+0x75): undefined reference to `displayPay()'
// collect2: error: ld returned 1 exit status
// this is the description of what I have to code and I have included my code 
// below any help would be appreciated
// Include these 3 functions:
// getSalesAmt
// -This function prompts the user to enter a monthly sales amount.
// -The amount is read and assigned to a variable.
// -The value is then returned to main()
// calcCommission
// -This function calculates the commission based on the sales amount.
// -If a salesperson sells more than $50,000. per month, the commission is 2% 
// of the sales amount.
// -If the sales are between $25,000 and $50,000., then the commission is 1.5% 
// of the sales amount.
// -However, if the sales are less than $25,000., there is no commission.
// -The value is returned to main().
// calcPay
// -This function calculates the total monthly pay for a salesperson.
// -A salesperson gets a monthly salary of $2,500. plus a commission, if the person earned a commission.
// -The value is returned to main().
// displayPay
// -This function displays the total monthly pay for a salesperson.
// -Format the output to two decimal places, and with the amounts aligned as shown.
#include <iomanip>
#include <iostream>

double getSalesAmt();
double calcCommission(double sales);
double calcPay(double pay, double commission);
void displayPay(double sales, double commission, double pay, double totalPay);

int main()
{
    double sales = getSalesAmt();
    double commission = calcCommission(sales);
    double pay = 2500;
    double totalPay = calcPay(pay, commission);
    displayPay(sales, commission, pay, totalPay);
    return 0;
}

// getSalesAmt
// -This function prompts the user to enter a monthly sales amount.
// -The amount is read and assigned to a variable.
// -The value is then returned to main()
double getSalesAmt()
{
    std::cout << "Enter the monthly sales amount: ";
    double sales;
    std::cin >> sales;
    return sales;
}

// calcCommission
// -This function calculates the commission based on the sales amount.
// -If a salesperson sells more than $50,000. per month, the commission is 2% 
// of the sales amount.
// -If the sales are between $25,000 and $50,000., then the commission is 1.5% 
// of the sales amount.
// -However, if the sales are less than $25,000., there is no commission.
// -The value is returned to main().
double calcCommission(double sales)
{
    double commission {};
    if (sales > 50000) {
        commission = sales * 0.02;
    } else if (sales > 25000 && sales < 50000) {
        commission = sales * 0.015;
    } else {
        commission = 0;
    }
    return commission;
}

// calcPay
// -This function calculates the total monthly pay for a salesperson.
// -A salesperson gets a monthly salary of $2,500. plus a commission, if the person earned a commission.
// -The value is returned to main().
double calcPay(double pay, double commission)
{
    return pay + commission;
}

// displayPay
// -This function displays the total monthly pay for a salesperson.
// -Format the output to two decimal places, and with the amounts aligned as shown.
void displayPay(double sales, double commission, double pay, double totalPay)
{
    std::cout << std::fixed << std::setprecision(2)
              <<   "Monthly Sales: $ " << sales
              << "\nCommission:    $ " << commission
              << "\nBase Pay:      $ " << pay
              << "\nTotal Pay:     $ " << totalPay << '\n';
}

Hello beginnercoder1,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

Check your prototypes against the function definitions and notice the number of parameters in each.

I would also suggest using "double"s over "float"s. "double" is more common these days and it has better precision than a float.

Hope that helps,

Andy
Topic archived. No new replies allowed.