calculate amount of salary received based on position level using C++

AkademiFantasia

Estimable
Sep 27, 2015
3
0
4,510
Here the question.

A company owned by First Avenue has a salary system based on position level. Employee salary is being paid on a weekly basis. The company has 30 employees, which comprises of a manager (fixed salary), cooks (salary on hourly basis), salesperson (fixed salary and sales commission). Below shows the details of salary payment for each position level.

1) Position level : Manager
Salary paid per week : Fixed salary

2) Position level : Cooks
Salary paid per week : First 30 hours - fixed rate every hour. The next following hours, overtime rate at 1.5% of the fixed rate hourly

3) Position level : Salesperson
Salary paid per week : $300 plus commission 8.5% of the total sales per week.

Calculate the amount of salary received for each employee based on their position level in the company.

Given is the input, output, solution/formula, and constraint for the above problem :

Inputs:
*fixed input:
- fixed salary for a manager
- fixed rate for cooks
- basic salary for salesperson
- commission rate

*user’s input:
- position category
- total working hours for cooks
- total sales for salesperson

Outputs:
- position category
- total income

Solution/Formula:
1) Income for a manager is fixed

2) Income for cooks is calculated by multiply total working hours with fixed rate:

2.1 if total working hours less than or equal 30 hours,
Total income = total working hours * fixed rate
2.2 if total working hours more than 30 hours
Total income = 30 * fixed rate + total working hours – 30 * 1.5 * fixed rate

3) Total income for a salesperson = $300 + commission rate * total sales per
week


Constraints:
- total working hours can not exceed than 168 hours
- total working hours must be entered for cooks
- total sales must be entered for salesperson

so, have to write a C++ program to calculate.


here is the code that i have done :

#include <iostream>
using namespace std;

int main(){
double managersalary, cooksfixedrate, salespersonsalary, commissionrate, cookstotalworkinghours, salespersontotalsales, totalincome;
char position, manager, cooks, salesperson;

managersalary = 1000.00;
cooksfixedrate = 15.00;
salespersonsalary = 300.00;
commissionrate = 0.085;
position = manager, cooks, salesperson;

cout << "Position category : ";
cin >> position;

if (position = manager)
{
totalincome = managersalary;
}

else if (position = cooks)
{
cout << "input total working hours : ";
cin >> cookstotalworkinghours;
if (cookstotalworkinghours <= 30)
{
totalincome = cookstotalworkinghours * cooksfixedrate;
cout << "total income : " << totalincome;
}
else if (cookstotalworkinghours > 30);
totalincome = (30 * cooksfixedrate) + cookstotalworkinghours - (30*1.5*cooksfixedrate);
cout << "total income : " << totalincome;
}

else if (position = salesperson)
{
cout << "total sales per week : ";
cin >> salespersontotalsales;

totalincome = 300 + (commissionrate * salespersontotalsales);
cout << "total income : "; <<totalincome;
}

return 0;

}

got many errors though..
is my code is correct to calculate the salary ?
 

giantbucket

Honorable
Nov 17, 2013
192
0
10,710
ok. then write it! evidently YOU have to write the C++ program. we don't have to write it. or are you trying to say "do my work for me so that i can pass my classes or get a promotion at MY job"..?
 

DSzymborski

Distinguished
Moderator
Why do I have to write a C++ program? I'm a journalist in my late 30s and haven't sat in a classroom in 15 years.

Oh, *you* have to write a C++ program? How did we get involved here? Maybe you should get to work rather than homework panhandling.
 

itmoba

Estimable
Aug 14, 2015
153
0
4,660
Code:
#include <iostream>
#include <cstdio>
int main(int argc, char *argv[], char *envp[]) {
     std::cout << "Do your own darn homework!" << std::endl;
     return (printf("poop\n"));
}
 

AkademiFantasia

Estimable
Sep 27, 2015
3
0
4,510


sorry, here is the code that i have done :

#include <iostream>
using namespace std;

int main(){
double managersalary, cooksfixedrate, salespersonsalary, commissionrate, cookstotalworkinghours, salespersontotalsales, totalincome;
char position, manager, cooks, salesperson;

managersalary = 1000.00;
cooksfixedrate = 15.00;
salespersonsalary = 300.00;
commissionrate = 0.085;
position = manager, cooks, salesperson;

cout << "Position category : ";
cin >> position;

if (position = manager)
{
totalincome = managersalary;
}

else if (position = cooks)
{
cout << "input total working hours : ";
cin >> cookstotalworkinghours;
if (cookstotalworkinghours <= 30)
{
totalincome = cookstotalworkinghours * cooksfixedrate;
cout << "total income : " << totalincome;
}
else if (cookstotalworkinghours > 30);
totalincome = (30 * cooksfixedrate) + cookstotalworkinghours - (30*1.5*cooksfixedrate);
cout << "total income : " << totalincome;
}

else if (position = salesperson)
{
cout << "total sales per week : ";
cin >> salespersontotalsales;

totalincome = 300 + (commissionrate * salespersontotalsales);
cout << "total income : "; <<totalincome;
}

return 0;

}

got many errors though..
is my code is correct to calculate the salary ?
 

AkademiFantasia

Estimable
Sep 27, 2015
3
0
4,510

sorry, here is the code that i have done :

#include <iostream>
using namespace std;

int main(){
double managersalary, cooksfixedrate, salespersonsalary, commissionrate, cookstotalworkinghours, salespersontotalsales, totalincome;
char position, manager, cooks, salesperson;

managersalary = 1000.00;
cooksfixedrate = 15.00;
salespersonsalary = 300.00;
commissionrate = 0.085;
position = manager, cooks, salesperson;

cout << "Position category : ";
cin >> position;

if (position = manager)
{
totalincome = managersalary;
}

else if (position = cooks)
{
cout << "input total working hours : ";
cin >> cookstotalworkinghours;
if (cookstotalworkinghours <= 30)
{
totalincome = cookstotalworkinghours * cooksfixedrate;
cout << "total income : " << totalincome;
}
else if (cookstotalworkinghours > 30);
totalincome = (30 * cooksfixedrate) + cookstotalworkinghours - (30*1.5*cooksfixedrate);
cout << "total income : " << totalincome;
}

else if (position = salesperson)
{
cout << "total sales per week : ";
cin >> salespersontotalsales;

totalincome = 300 + (commissionrate * salespersontotalsales);
cout << "total income : "; <<totalincome;
}

return 0;

}

got many errors though..
is my code is correct to calculate the salary ?
 

itmoba

Estimable
Aug 14, 2015
153
0
4,660


No. Your code has a few glaring problems. Firstly, we're talking about C++, not C. Therefore, while it's sometimes acceptable to write main() in C, in C++ it should be main(int argc, char *argv[]). The function parameter of the second argument may also be const char *argv[], or const char * const argv[], or char **argv. There're a few other variations, but those are the most common.

Okay, now, whilst you technically used using namespace, I'm going to continue to use '::' for scope resolution, as your use of namespaces shouldn't be used by beginners (in my opinion, because it should only be used as a quick lazy cheat by people who know what they're doing). That said, there's a major difference between = and ==. The former is an assignment operator, whilst the latter is a comparison operator (equality). Let's look at the following example:
C:
int blah = 7;
if (blah = 8) {
        std::cout << blah;
} else {
        std::cout << "wtf?";
}
In this example, ostream (i.e., the output stream of cout to STDOUT) shall always return 8. This is because the assignment operator (=) was used. However, if it were:
C:
int blah = 7;
if (blah == 8) {
        std::cout << blah;
} else {
        std::cout << "wtf?";
}
Then, ostream (i.e., the output stream of cout to STDOUT) shall always return the string "wtf?". This is because the comparison operator (==) was used.

Lastly, your nesting is completely borked. Please learn about curly-brace placements (i.e., { and }).
 

rgd1101

Don't
Moderator


got many errors? then fix it, it call debug.
 

itmoba

Estimable
Aug 14, 2015
153
0
4,660


rgd1101, you bring up a very valuable point and lesson for the OP :lol:.

That aside, this reminds me to ask AkademiFantasia the following:
(1) Which OS are you using?
(2) Which OS are you developing on?
(3) Which IDE are you using?

(Note: Numbers 1 and 2 may seem similar, but in the case of VMs, for instance, there's a noticeable difference.)