Need Help With Functions

Feb 23, 2015 at 4:25am
closed account (E8AXSL3A)
I am writing a code that requires the three functions listed. I keep getting the following error messages and I absolutely do not know what to do. Any help is appreciated!!

Error 6 error C2082: redefinition of formal parameter 'commissionOwed' c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 42 1 Chp 10 Commiss Lab Test
Error 2 error C2440: '==' : cannot convert from 'double (__cdecl *)(double)' to 'double' c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 17 1 Chp 10 Commiss Lab Test
Error 4 error C2440: '==' : cannot convert from 'double (__cdecl *)(void)' to 'double' c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 18 1 Chp 10 Commiss Lab Test
Error 1 error C2446: '==' : no conversion from 'double (__cdecl *)(double)' to 'double' c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 17 1 Chp 10 Commiss Lab Test
Error 3 error C2446: '==' : no conversion from 'double (__cdecl *)(void)' to 'double' c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 18 1 Chp 10 Commiss Lab Test
Error 5 error C3861: 'displayCommission': identifier not found c:\users\alec\documents\visual studio 2013\projects\chp 10 commiss lab test\chp 10 commiss lab test\source.cpp 19 1 Chp 10 Commiss Lab Test
8 IntelliSense: cannot determine which instance of overloaded function "getCommission" is intended c:\Users\Alec\Documents\Visual Studio 2013\Projects\Chp 10 Commiss Lab Test\Chp 10 Commiss Lab Test\Source.cpp 18 20 Chp 10 Commiss Lab Test
7 IntelliSense: operand types are incompatible ("double" and "double (*)(double monthlySales)") c:\Users\Alec\Documents\Visual Studio 2013\Projects\Chp 10 Commiss Lab Test\Chp 10 Commiss Lab Test\Source.cpp 17 14 Chp 10 Commiss Lab Test

--------------------------------------------



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

//Function Prototype
double getMonthlySales(double);
double getCommission();
void diplayCommission(double commissionOwed);

int main()
{
	//Declare Variables
	double salesAmount = 0.0;
	double commissionOwed = 0.0;

	//Call Functions to Calculate the Employees Commission Owed
	salesAmount == getMonthlySales;
	commissionOwed == getCommission;
	displayCommission(commissionOwed);
	


	system("pause");
	return 0;

}
//End of Main Function


//**Function Definitions**
double getMonthlySales(double monthlySales)
{
	double salesAmount = 0.0;
	cout << "Enter Your Total Monthly Sales :$" << endl;
	cin >> salesAmount;
	return salesAmount;
}
//End of Get Monthly Sales Function

double getCommission(double commissionOwed, double salesAmount)
{
	double commissionOwed = 0.0;

	if (salesAmount > 0 && salesAmount <= 19999)
		commissionOwed = salesAmount*.04;
	else if (salesAmount >= 20000 && salesAmount <= 29999)
		commissionOwed = salesAmount*.05;
	else if (salesAmount >= 30000 && salesAmount <= 39999)
		commissionOwed = salesAmount*.06;
	else if (salesAmount >= 40000 && salesAmount <= 49999)
		commissionOwed = salesAmount*.07;
	else  (salesAmount >= 50000);
	commissionOwed = salesAmount*.08;
	
	return commissionOwed;
}
//End of Get Commission Function

void displayCommission(double commissionOwed)
{
	cout << "Total Commission: $" << fixed << setprecision(2) << commissionOwed << endl;
}
//End of Display Commission Function



Last edited on Feb 23, 2015 at 4:43am
Feb 23, 2015 at 4:30am
Please post your question in code tags
its harder to read the way you have it posted.
Also you are more likely to get help if you do so.
http://www.cplusplus.com/articles/jEywvCM9/
Feb 23, 2015 at 4:33am
closed account (E8AXSL3A)
I'm sorry I am still new and learning C++, what do you mean by code tags?
Feb 23, 2015 at 4:34am
Feb 23, 2015 at 4:35am
closed account (E8AXSL3A)
Sorry thanks, is that the proper way to post questions on forum?
Feb 23, 2015 at 4:41am
Np. I wouldn't sweat it too much, using code tags will increase your chances of getting help.
Feb 23, 2015 at 4:46am
you have a few issues. Lets start with one at at time.

1
2
3
double getMonthlySales(double);
double getCommission();
void diplayCommission(double commissionOwed);


the above is wrong.
do you know why?

Feb 23, 2015 at 4:51am
closed account (E8AXSL3A)
Not too sure, but I can take a guess... should the parentheses be empty? (not say double etc)
Feb 23, 2015 at 4:56am
look at this.
http://www.cplusplus.com/doc/tutorial/functions/
then guess again. you sound like your on the right track.
it all boils down too what you want to do.
Last edited on Feb 23, 2015 at 4:57am
Feb 23, 2015 at 5:01am
closed account (E8AXSL3A)
I think it has something to do with how I'm naming my variables? I am honestly clueless my brain is fried haha
Feb 23, 2015 at 5:05am
closed account (E8AXSL3A)
I think I have a problem with updating the variable and it following through the whole code through each function...?
Feb 23, 2015 at 5:15am
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
#include<iostream>
#include<iomanip>
using namespace std;

//Function Prototype
//double getMonthlySales(double);
int getMonthlySales(); // input: nothing   return: monthly sales amount
                       // sales amount is an integer
                       // (because we have <= 19999 and next >= 20000)

// double getCommission();
double getCommission( int salesAmount ) ; // input: sales amount   return: commission

// void diplayCommission(double commissionOwed);
void displayCommission(double commissionOwed); // input: commission   return: nothing

int main()
{
    /*
	//Declare Variables
	double salesAmount = 0.0;
	double commissionOwed = 0.0;

	//Call Functions to Calculate the Employees Commission Owed
	salesAmount == getMonthlySales;
	commissionOwed == getCommission;
	displayCommission(commissionOwed);
    */

    const int salesAmount = getMonthlySales() ;
    const double commissionOwed = getCommission(salesAmount) ;
    displayCommission(commissionOwed) ;


	// system("pause");
	//return 0;

}
//End of Main Function


//**Function Definitions**
// double getMonthlySales(double monthlySales)
int getMonthlySales()
{
	// double salesAmount = 0.0;
	int salesAmount = 0 ;
	cout << "Enter Your Total Monthly Sales :$" << endl;
	cin >> salesAmount;
	return salesAmount;
}
//End of Get Monthly Sales Function

// double getCommission(double commissionOwed, double salesAmount)
double getCommission( int salesAmount )
{
        double commissionOwed = 0.0;

	if (salesAmount > 0 && salesAmount <= 19999)
		commissionOwed = salesAmount*.04;
	else if (salesAmount >= 20000 && salesAmount <= 29999)
		commissionOwed = salesAmount*.05;
	else if (salesAmount >= 30000 && salesAmount <= 39999)
		commissionOwed = salesAmount*.06;
	else if (salesAmount >= 40000 && salesAmount <= 49999)
		commissionOwed = salesAmount*.07;
	// else  (salesAmount >= 50000);
	else // (salesAmount >= 50000)
	    commissionOwed = salesAmount*.08;

	return commissionOwed;
}
//End of Get Commission Function

void displayCommission(double commissionOwed)
{
	cout << "Total Commission: $" << fixed << setprecision(2) << commissionOwed << endl;
}
//End of Display Commission Function 
Feb 23, 2015 at 5:32am
First problem, don't do this.
double getMonthlySales(double); In your function prototype: Name the variable inside your function parameters. For example, instead of

double getMonthlySales(double); use something so that you will know what you are doing i.e. -> getMonthlySales(double monthlySales);

Also there are other problems in your code. Let's start with the first one.

Your code:
salesAmount == getMonthlySales;

You're saying "Is the data in salesAmount equivalent to the getMonthlySales variable's data ? The problem is getMonthlySales isn't a variable, no where have you defined it anywhere in your main function code. I think what you are trying to say is take the result of what the getMonthlySales(double imAVariableName) function returns and store it in the variable salesAmount

If that's the case you will have to use the assignment operator which is =

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
//Using the assignment operator
int imaVar; //Declares a variable imaVar of type integer
imaVar = 33; //Initializes the variable imaVar with data. i.e. ASSIGNS the number 33 to the
                     //variable imaVar

//Using the equivalent to operator
bool cat = true; //Assignment operator again used to initialize and declare the variables
bool dog = false; // ^
int userinput;

//Assume a user already has a cat (this is just an example)
//Assume the user enters 1 for input
cout << "If you have a dog type 1 "; cin >> userinput;
//If the user has a dog, set dog to be TRUE
  if(userinput == 1)
    dog = true;

//NOTE: Remember that = is NOT THE SAME as ==
//When you say int variableName == 1 you are NOT assigning 1 to that variable! 

//Now using the equivalent to operator
if(dog == cat) //If DOG (true) is equal to CAT(true) then proceed
  cout << "You have a DOG and a CAT!" << endl;


//Since dog = true & cat = true also then True & True evaluates to True
//Therefore the expression will evaluate to true? Make sense?


Instead I think what you are looking for is something like this:

1
2
3
4
5
6
7
8
9
10
//Declare Variables
	double salesAmount = 0.0;
	double commissionOwed = 0.0;
	double monthlySales = 0.0; //declares a variable for you to pass through your function, you do want to use your function right?

         cout << "What is your monthly sales?"; cin >> monthlySales;
	//Call Functions to Calculate the Employees Commission Owed
	salesAmount = getMonthlySales(monthlySales); //What this will do is set whatever  
       //double you returned from the getMonthlySales(double imaVarName) function to the   
       //variable salesAmount as it looks like you want it to 


Note: There are still more problems in the code. Let me know if you have any questions about what I'm saying.
Last edited on Feb 23, 2015 at 5:42am
Feb 23, 2015 at 5:35am
closed account (E8AXSL3A)
Wow you are the man, I am still reading through the code but could you point out the main changes/errors I had?
Feb 23, 2015 at 5:52am
My revisions or JLBorges?
Feb 23, 2015 at 5:59am
closed account (E8AXSL3A)
@shamieh I can follow your changes since you broke it off into a block, I was referring to JLBorges
Feb 23, 2015 at 6:01am
@jrob Also notice that JLBorges took the parameters out of your getMonthlySales function. Not sure if that was a requirement of your teacher or not, but with JLBorges solution you can not do what I proposed above. Nevertheless, his solution is still a valid solution.
Feb 23, 2015 at 6:21am
> could you point out the main changes/errors I had?

Your original code is commented out, and just below it is the changed code.
For example:
1
2
3
4
5
//double getMonthlySales(double); *** this was the original code ****

int getMonthlySales(); // input: nothing   return: monthly sales amount
                       // sales amount is an integer
                       // (because we have <= 19999 and next >= 20000) 


In general, when we consider a function, we should be thinking about:
a. What does this function accept as input?
b. What does it do?
c. What does it return as the result?

When we write the function, it would accept the inputs, do what it does and return a result (if any).

When we call the function, we would pass the input arguments, and use the result that it returns.

For example: pass salesAmount as the input to the function, and store the result returned in commissionOwed

const double commissionOwed = getCommission(salesAmount) ;
Topic archived. No new replies allowed.