output for the first input should not be same as for second user input..but it occurs to be same.

#include <iostream>
#include <iomanip>
using namespace std;

//function prototype
void show(void);
void display(void);
double totalsales(double sales1, double sales2, double sales3);

//double grandtotal(double totalsales1, double totalsales2, double totalsales3);

int main()
{
//variable declaration

int level;
double hours, overtime_rate;
double total = 0;
const int salesperson = 2;
string employee[salesperson];
string best_employee_display;
const double price_product1 = 100.00;
const double price_product2 = 50.00;
const double price_product3 = 10.00;
double product1, product2, product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
cout << endl;
break;


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

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


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


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

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


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;
}

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";
}

double totalsales(double sales1, double sales2, double sales3)
{
double totalsales;
totalsales = (sales1 + sales2 + sales3);
return totalsales;
}

Last edited on
Since it's your first post here let me give you some advices:

Use code brackets for publishing your code: it's the first button bottom-right.

Inform about the actual problem providing some information:
What your program is supposed to do.
What is the problem you are facing.
Where it occurs (line of code, function etc)
What are the errors of the compiler?

Don't just write a comment to the title.
Your code 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
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
#include <iostream>
#include <iomanip>
using namespace std;

//function prototype
void show(void);
void display(void);
double totalsales(double sales1, double sales2, double sales3);

//double grandtotal(double totalsales1, double totalsales2, double totalsales3);

int main()
{
//variable declaration

int level;
double hours, overtime_rate;
double total = 0;
const int salesperson = 2;
string employee[salesperson];
string best_employee_display;
const double price_product1 = 100.00;
const double price_product2 = 50.00;
const double price_product3 = 10.00;
double product1, product2, product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
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;
cout << "PRODUCT 2 SOLD: " ;
cin >> product2;
cout << "PRODUCT 3 SOLD: " ;
cin >> product3;
cout << endl;
break;


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

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


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


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

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


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;
}

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";
}

double totalsales(double sales1, double sales2, double sales3)
{
double totalsales;
totalsales = (sales1 + sales2 + sales3);
return totalsales;
}
Last edited on
thank you very much for your advises..
sorry. it's my first time and i'm not getting used with this forum..
i'll try my best to improve and learn..

this program was supposed to calculate the amount of sales of three products made by the salespersons. the problem occur is that the output is wrong and i can't identify where it is. i had done this coding for only one salesperson and it's work. but, when i just change to make it more salespersons (line 19) the output for the previous salespersons is just as the same with the last salesperson based on the user input for that particular salesperson.

why is it happen and how am i suppose to correct it?? need some guidance..
Topic archived. No new replies allowed.