need explanation and guidance

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include <iostream>
#include <iomanip>
using namespace std;

//function prototype
void show(void);
void display(void);
void summary(void);
//double grandtotal(double totalsales);


int main()
{
    //variable declaration

    int level;
    double hours, overtime_rate, grosspay;
    double total = 0;
    const int salesperson = 4;
    int best_employee;
    string employee[salesperson];
    string best_employee_display;
    const double price1 = 100.00;
    const double price2 = 50.00;
    const double price3 = 10.00;
    int product1[salesperson];
    int product2[salesperson];
    int product3[salesperson];
    double sales1[salesperson];
    double sales2[salesperson];
    double sales3[salesperson];
    double totalsales[salesperson];
    double grandtotal;


    show();

    for (int i=0; i<salesperson; i++)
    {
        cout << "NAME OF EMPLOYEE: " ;
        cin >> employee[i] ;
        cout << "CURRENT LEVEL (1/2/3): ";
        cin >> level;

    switch (level)
    {
        case 1:
            cout << "Professional\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                    {
                        if (level==1)
                        {
                            overtime_rate = hours * 20;
                        }
                        else if (level==2)
                        {
                            overtime_rate = hours * 10;
                        }
                        else
                            overtime_rate = hours *5;
                    }

            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1[i];
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2[i];
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3[i];
            cout << endl;
            break;

        case 2:
            cout << "Armatur\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                {
                    if (level==1)
                    {
                        overtime_rate = hours * 20;
                    }
                    else if (level==2)
                    {
                        overtime_rate = hours * 10;
                    }
                    else
                        overtime_rate = hours *5;
                }
            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1[i];
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2[i];
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3[i];
            cout << endl;
            break;

        case 3:
            cout << "Trainee\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                {
                    if (level==1)
                    {
                        overtime_rate = hours * 20;
                    }
                    else if (level==2)
                    {
                        overtime_rate = hours * 10;
                    }
                    else
                        overtime_rate = hours *5;
                }

            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1[i];
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2[i];
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3[i];
            cout << endl;
            break;


        default:
            cout << "Invalid! Please refer to HR Department.\n\n";
            break;

        }//end of switch case
    }//end of for loop


    for (int j=0; j<salesperson; j++)
    {
        sales1[j] = total + (product1[j]*price1);
        sales2[j] = total + (product2[j]*price2);
        sales3[j] = total + (product3[j]*price3);
        totalsales[j] = sales1[j] + sales2[j] + sales3[j];
    }


    for (int m=0; m<salesperson; m++)
    {
        sales1[m] = total + (product1[m]*price1);
        sales2[m] = total + (product2[m]*price2);
        sales3[m] = total + (product3[m]*price3);
        totalsales[m] = sales1[m] + sales2[m] + sales3[m];
    }

    for (int p=0; p<salesperson; p++)
    {
        sales1[p] = total + (product1[p]*price1);
        sales2[p] = total + (product2[p]*price2);
        sales3[p] = total + (product3[p]*price3);
        totalsales[p] = sales1[p] + sales2[p] + sales3[p];
    }



    //for(int z=0; z<salesperson; z++)
    //{
        //if (totalsales[z] > (totalsales[z+1])){
            //if (totalsales[z]> best_employee){
            //best_employee = totalsales[z];
                //if(best_employee >= totalsales[z]);
                //best_employee_display = employee[z];
            //}
       //}
    //}

    display();

    cout << "_____________________________________________________"
		 << "__________________________";
    cout << "\nEmployee\tProduct1\tProduct2\tProduct3\tTotal Sales(RM)"<< endl;
    cout << "_____________________________________________________"
		 << "__________________________\n";



    for (int k=0; k<salesperson; k++)
    {
        cout << employee[k] << "\t\t" << fixed << setprecision(2)
             << sales1[k] << "\t\t" << fixed << setprecision(2)
             << sales2[k] << "\t\t" << fixed << setprecision(2)
             << sales3[k] << "\t\t" << fixed << setprecision(2)
             << totalsales[k] << "\t\t" << fixed << setprecision(2) << endl;
    }


    cout << "\n_____________________________________________________"
		 << "__________________________\n"
         << setw(76) << " Grand Total\n"
         << setw(76) << "-----------\n";

    for (int b=0; b<salesperson; b++)
        grandtotal += totalsales;

    cout << "\t\t\t\t\t\t\t\t" << grandtotal;
    cout << "\n\t\t\t\t\t\t\t\t-----------\n";


    summary();

    cout << "_____________________________________________________"
             << "__________________________";
    cout << "\nEmployee\tOvertime Rate(RM)\tTotal Sales(RM)\t\tGross Pay(RM)"<< endl;
    cout << "_____________________________________________________"
		 << "__________________________\n";


    for(int a=0; a<salesperson; a++)
    {
        grosspay = (overtime_rate + totalsales[a]);
        cout << employee[a] << "\t\t" << fixed << setprecision(2)
             << [b]overtime_rate << "\t\t\t" << fixed << setprecision(2)
             << totalsales[a] << "\t\t\t" << fixed <<setprecision(2)
             << grosspay << "\t\t" << fixed << setprecision(2) <<endl;
    }



    cout << "\n_____________________________________________________"
		 << "__________________________\n";
    cout << "\n\t\t\t***END OF PROGRAM***\n\n";


return 0;
}

void show(void)
{

    cout << "\tThis is a program that will print out a sale slip for three"
         << "\n\tsalespersons. There are three levels or current position"
         << "\n\tor job which is professional,armature and trainee.For each"
         << "\n\tlevel of job, it will be differences in the rate of working"
         << "\n\tovertime. Each salesperson has to sell three products."<<endl
         << "-----------------------------------------------------"
         << "--------------------------\n\n\n";
}

void display(void)
{
    cout << "\n\tThe total sales for each sales person are displayed at the"
         << "\n\tend of each row. Price for Product1 is RM100. Price for"
         << "\n\tProduct2 is RM50. And the price for Product3 is RM10."
         << "\n-----------------------------------------------------"
         << "--------------------------\n\n\n"
         << "\t\t<--------------- Products ------------->\n";
}

void summary(void)
{
    cout << "\n-----------------------------------------------------"
         << "--------------------------\n\n\n"
         << "\n\n\n\t\tThis is the overall summary for all data :" <<endl;

}


i've done to correct the previous error and got it correct. thanks to all of you.
now, i'm facing another little problem which is another one more error occur in this loop :


for(int a=0; a<salesperson; a++)
{
grosspay = (overtime_rate + totalsales[a]);
cout << employee[a] << "\t\t" << fixed << setprecision(2)
<< overtime_rate[a] << "\t\t\t" << fixed << setprecision(2)
<< totalsales[a] << "\t\t\t" << fixed <<setprecision(2)
<< grosspay << "\t\t" << fixed << setprecision(2) <<endl;
}

i've run this program without the [a] in the overtime_rate, but the output is not correct.
it supposed to be that i must put the [a]. but when i put it there, error occur and i am clueless what is the error exactly. i trust that someone know about this.
Back where you declare overtime_rate, try-
overtime_rate[salesperson]

Then, when you're modifying overtime_rate, change this-
1
2
3
4
5
6
7
8
9
10
11
12
13
            cin >> hours;
                    {
                        if (level==1)
                        {
                            overtime_rate = hours * 20;
                        }
                        else if (level==2)
                        {
                            overtime_rate = hours * 10;
                        }
                        else
                            overtime_rate = hours *5;
                    }


to this-

1
2
3
4
5
6
7
8
9
10
11
12
13
            cin >> hours;
                    {
                        if (level==1)
                        {
                            overtime_rate[i] = hours * 20;
                        }
                        else if (level==2)
                        {
                            overtime_rate[i] = hours * 10;
                        }
                        else
                            overtime_rate[i] = hours *5;
                    }


for all your cases. Then at the end you can read out
1
2
3
4
5
6
7
8
for(int a=0; a<salesperson; a++)
{
grosspay = (overtime_rate[a] + totalsales[a]); // Added [a] to overtime_rate here.
cout << employee[a] << "\t\t" << fixed << setprecision(2)
<< overtime_rate[a] << "\t\t\t" << fixed << setprecision(2)
<< totalsales[a] << "\t\t\t" << fixed <<setprecision(2)
<< grosspay << "\t\t" << fixed << setprecision(2) <<endl;
}
Last edited on
yes! it's work! thank you very much! :))
Topic archived. No new replies allowed.