help !

iam getting one compiling error please help

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
 #include<stdio.h>
#include<iostream>                  //headers
#include<string>
using namespace std;

class SalesRep                         //declared the class
{
    private:
    string name;
    double salesamt1;
    double salesamt2;
    
    public:
    SalesRep()                             //default constructor
    {
        name="Bruce";
        salesamt1=1234.67;
        salesamt2=6789.89;
    }
    
    SalesRep(string Name, double Salesamt1, double Salesamt2)  //parametized constructor
    {
        name=Name;
        salesamt1=Salesamt1;
        salesamt2=Salesamt2;
        
    }
    
    void setname(string sname);
    string getname();
    void setprd1(double ssalesamt1 );
    double getprd1();
    void setprd2(double ssalesamt2);
    double getprd2();
    double getsales();
   double getcommisions();
   float calcPay(float commission);
   
    
    
};

void SalesRep::setname(string sname)
{
    name=sname;
}
string SalesRep:: getname()
{
    return name;
}
void SalesRep:: setprd1(double ssalesamt1 )
{
  salesamt1=ssalesamt1;   
}
double SalesRep:: getprd1()
{
    return salesamt1;
}
void SalesRep:: setprd2(double ssalesamt2)
{
    salesamt2=ssalesamt2;
}
double SalesRep:: getprd2()
{
    return salesamt2;
}
double SalesRep:: getsales()
{
    int salesAmt;

	cout << "Enter a monthly sales amount: ";
	cin >> salesAmt;

	return salesAmt;
}
double SalesRep:: getcommisions()
{
    
    float commission;

	if(salesAmt <=8000)
commission = .10 * salesAmt

else if (salesAmt >=4000 && <=8000)
commission = .07 * salesAmt

else if (salesAmt<4000)
commission = .10 * salesAmt

else //anything over 4000
commission = 0 * salesAmt

	return commission;
}
float SalesRep:: calcPay(float commission)
{
	float totalPay;

	//basePay = commission * salesAmt;

	return totalPay;
}

int main()
{
   

    return 0;
}
Are you serious or do you kidding us? The compiler messages are clear and unambiguous. If you click on the gear (at the right side on top of your listing) you could even fix your example with the browser.
Hello poohbear,

You should always compile your program before posting. This way if there any error messages that yo do not understand you can include them. It is best to post the actual complete error message.

In the function "getcommisions()" there are 8 errors that need to be corrected. I will give you a hint on one else if (salesAmt >=4000 && <=8000). This is wrong. On the rhs of && there is nothing to evaluate. It should be else if (salesAmt >=4000 && salesAmt <=8000). Your way would be nice, but that is not the way C++ is designed.

As nuderobmonkey suggested use the gear icon at the top right of the code block. When you press "run" the compiler will give you the errors and warnings.

Such as:

 In member function 'double SalesRep::getcommisions()':
 81:5: error: 'salesAmt' was not declared in this scope
 94:1: warning: no return statement in function returning non-void [-Wreturn-type] 


The first error is simple the variable "salesAmt" was not defined anywhere in the function.

I do agree that the warning is harder to understand. First keep in mind that the warning is on the closing brace of the function. This is not where the error has started. It actually started at line 82.

A push in the right direction. You have the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
double SalesRep:: getcommisions()
{
    
    float commission;

	if(salesAmt <=8000)
commission = .10 * salesAmt

else if (salesAmt >=4000 && <=8000)
commission = .07 * salesAmt

else if (salesAmt<4000)
commission = .10 * salesAmt

else //anything over 4000
commission = 0 * salesAmt

	return commission;
}


With proper indenting it would look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
double SalesRep::getcommisions()
{

	float commission;

	if (salesAmt <= 8000)
		commission = .10 * salesAmt

	else if (salesAmt >= 4000 && <= 8000)
		commission = .07 * salesAmt

	else if (salesAmt < 4000)
		commission = .10 * salesAmt

	else //anything over 4000
		commission = 0 * salesAmt

		return commission;
}


But the compiler will see something like this:
1
2
3
4
5
6
7
double SalesRep::getcommisions()
{

	float commission;

	if(salesAmt<8000)commission=.10*salesAmtelseif(salesAmt>4000&&<=8000)commission=.07*salesAmtelseif(salesAmt<4000)commission=.10*salesAmtelse /*anything over 4000*/commission=0 salesAmtreturn commission;
}

I took out all the spaces because the compiler does not care about white space. The point is that this is what the compiler is likely seeing.

Now thinking back to something that you should have already learned the a semi-colon ends a line of with some exceptions like an if statement. Now look back over your code and find what is missing.

All that is left if to figure where "salesAmt" comes from. Does it come into the function as a parameter or should it be defined as a member variable of the class?

Hope that helps,

Andy
Topic archived. No new replies allowed.