//Program that computes for the salary of the employee

#include <iostream>
using namespace std;

int main()

{
    int EmployeeCode;
    float WeeklySalary, HourlyWage, NumHoursWorked, Overtime;
    
    cout<<"Enter Employee Code: ";
    cin>>EmployeeCode;        
    
    if (EmployeeCode==1)
       {
       cout<<"Enter Weekly Salary: $ ";
       cin>>WeeklySalary;
       WeeklySalary = WeeklySalary;
       cout<<"Weekly Salary is: $ "<<WeeklySalary;
       }
       else if (EmployeeCode==2)
            {    
            cout<<"Enter Hourly Wage $: ";
            cin>>HourlyWage;
            cout<<"Enter Number of Hours Worked: ";
            cin>>NumHoursWorked;
            
            if (NumHoursWorked <= 40) 
               {
               WeeklySalary = HourlyWage * NumHoursWorked;
               cout<<"Weekly Salary is: $ "<<WeeklySalary<<endl;
               }
            else
               {
               Overtime = NumHoursWorked - 40;
               WeeklySalary = (HourlyWage*40) + (Overtime*HourlyWage*1.5);
               cout<<"Weekly Salary is: $ "<< WeeklySalary;
               }
            }
       //else if
            
            
    cout<<"\n\nPress any key and ENTER to EXIT";
    
    char response;
    cin>> response;
    
    return 0;
}

Recommended Answers

All 14 Replies

Can't... You haven't provided us with a sufficient description of the problem. At this point, all we can do is guess...

Does the program compile? If not, what are the compile errors? If yes, what are you expecting the program to do and what is it doing incorrectly?

Also, please read about [code] ...code tags... [/code]. They are your friend. When properly used, you will generally get more, and better, help. But, you've been around long enough, you should know that by now.

EDIT:
Oops...Looks like you can thank Mr. Evan for fixing your tags...

yes the program compiles,
thanks for the time... as i go through again with the code, ive found out that there were no errors in my code... sorry for the disturbance...
thank you again... actually im not yet done with the whole program.. this is just a part...
i will post the whole problem given to us...

A company pays its employees as managers (who received a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and "time-and-a-half" - 1.5 times their hourly wage- for overtime hours worked), commission workers (who receive $250 plus 5.7 percent of their gross weekly sales), or pieceworkers (who received a fixed amount of money per item for each of the items the produce - each pieceworker in this company works on only one type of item). Write a program to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own paycode: Managers have code 1, hourly workers have code 2, commission workers have code 3 and pieceworkers have code 4. Use a "switch" to compute each employee's pay according to that employee's paycode. Within the "switch", prompt the user (i.e. payroll clerk) to enter the appropriate facts your program needs to calculate each employee's pay according to that employee's paycode.

You are to submit the following:
1. Algorithm/Pseudocode
2. Flowchart
3. Source Code
4. Sample Input/Output (at least one test data for each type of workers)

Actually, there is some redundancy that you should probably eliminate. Line 17 is a wasted command, it accomplishes nothing useful. The assignment you perform was already accomplished by the input statement.

Also, do you know anything about functions yet? There are some commands in here that it would do you well to make into a separate function. There are 3 locations where you output "Weekly salary is: $..."

You may want to take a look at the formatting as well. Lines 20 - 38 are a single else if block, but the indentation makes it look like a sub-block of the if above it. The logic is not easily discernible from the formatting.

else if (EmployeeCode==3)
            {
            cout<<"Enter Gross Weekly Sales: $ ";
            cin>>GrossWeeklySales;
            WeeklySalary = (GrossWeeklySales * .057) + 250;
            cout<<"Weekly Salary is: $ "<< WeeklySalary;
            }

this is the continuation of the codes... but this does not work... i do know a bit of functions but i can hardly use that...

this is the continuation of the codes... but this does not work... i do know a bit of functions but i can hardly use that...

A company pays its employees as managers ..., hourly workers ..., commission workers ..., or pieceworkers ...
<snip>
Write a program to compute the weekly pay for each employee. You do not know the number of employees in advance.

Okay, this looks like you need an indeterminate loop, I don't see a loop anywhere in your code...

Each type of employee has its own paycode: Managers have code 1, hourly workers have code 2, commission workers have code 3 and pieceworkers have code 4. Use a "switch" to compute each employee's pay according to that employee's paycode. Within the "switch", prompt the user (i.e. payroll clerk) to enter the appropriate facts your program needs to calculate each employee's pay according to that employee's paycode.

I don't see a switch either... I see a few nested ifs for paycodes 1 and 2, which accomplish the same thing, but don't accomplish this assignment objective.

that is my another problem, because i hate to use loops coz im confused... same with the switch...

The only way to understand them is to use them. You'll never get comfortable with them if you don't try. If you FUBAR it, that's what we're here for. Learn from the mistake, correct the error, and try again.

For this assignment, you need an indeterminate loop. An indeterminate loop is essentially an "infinite" loop. However, unlike a true infinite loop, it runs an unknown number of times then terminates under a certain condition. This is opposed to the determinate loop which runs a pre-determined number of times then terminates. Indeterminate loops are best implemented with either the while or do...while loop constructs.

int inputVar = 0; //declare an input variable
cin >> inputVar; //get seed input
while (inputVar >= 0) { //begin loop
  /* ... perform some actions ... */
  cin >> inputVar;  //get new input
} //end loop

The switch is a "shortcut" for an if...else if...else ladder.

switch (inputVar) {
  case 0:
    /*do something 0*/
    break;
  case 1:
    /*do something 1*/
    break;
  case 2:
    /*do something 2*/
    break;
  default:
    /*do something else*/
} //end switch

is functionally the same as:

if (inputVar == 0) {
  /*do something 0*/
}
else if (inputVar == 1) {
  /*do something 1*/
}
else if (inputVar == 2) {
  /*do something 2*/
}
else {
  /*do something else*/
}

You can find more information here...

can you give csha the whole program for the problem?pls?

commented: Absolutely not, cheater... +0
commented: Seconded -1

can you give csha the whole program for the problem?pls?

Absolutely not, it is against policy.

Of course, if I did, both of you would cut/paste it and hand it in without looking at it. This would afford me the opportunity to hide something in it for your instructor telling him to fail both you and your classmate (if you aren't already the same person, which I suspect you are) for cheating.

thanks for the advices.. i'll practice using those... thank you... il post again the program when im done... godbless

/*A company pays its employees as managers (who received a fixed weekly salary),
hourly workers (who receive a fixed hourly wage for up to the first 40 hours
they work and "time-and-a-half" - 1.5 times their hourly wage- for overtime 
hours worked), commission workers who receive $250 plus 5.7 percent of their 
gross weekly sales), or pieceworkers (who received a fixed amount of money per item 
for each of the items the produce - each pieceworker in this company 
works on only one type of item). Write a program to compute the weekly 
pay for each employee. You do not know the number of employees in advance. 
Each type of employee has its own paycode: Managers have code 1, hourly 
workers have code 2, commission workers have code 3 and pieceworkers have 
code 4. Use a "switch" to compute each employee's pay according to that 
employee's paycode. Within the "switch", prompt the user (i.e. payroll clerk) 
to enter the appropriate facts your program needs to calculate each employee's 
pay according to that employee's paycode.*/

#include <iostream>
using namespace std;

int main()

{
    int EmployeeCode, ItemsProduced;
    float WeeklySalary, HourlyWage, NumHoursWorked, Overtime, GrossWeeklySales, PaymentEachItem;
    
    cout<<"Enter Employee Code: ";
    cin>>EmployeeCode;        
    
    switch (EmployeeCode)
    {
//computes the weekly salary of managers
    case 1: cout<<"Enter Weekly Salary: $ ";
            cin>>WeeklySalary;
            cout<<"Managers Weekly Salary is: $ "<<WeeklySalary<<endl;
            break;
//computes the weekly salary of Hourly Workers
    case 2: cout<<"Enter Hourly Wage $: ";
            cin>>HourlyWage;   
            cout<<"Enter Number of Hours Worked: ";
            cin>>NumHoursWorked;
            {
            if (NumHoursWorked <= 40) 
               {
               WeeklySalary = HourlyWage * NumHoursWorked;
               cout<<"Hourly Workers Weekly Salary is: $ "<<WeeklySalary<<endl;
               }
            else
               {
               Overtime = NumHoursWorked - 40;
               WeeklySalary = (HourlyWage*40) + (Overtime*HourlyWage*1.5);
               cout<<"Hourly Workers Weekly Salary is: $ "<<WeeklySalary<<endl;
               }
            }   
            break;
//computes the weekly salary of Commission workers            
    case 3: cout<<"Enter Gross Weekly Sales: $ ";
            cin>>GrossWeeklySales;
            WeeklySalary = (GrossWeeklySales * .057) + 250;
            cout<<"Commission Workers Weekly Salary is: $ "<< WeeklySalary<<endl;
            break; 
//computes the weekly salary of Pieceworkers             
    case 4: cout<<"Enter Items Produced: ";
            cin>>ItemsProduced;
            cout<<"Enter the amount of payment per item: $";
            cin>>PaymentEachItem;  
            WeeklySalary = ItemsProduced*PaymentEachItem;
            cout<<"Pieceworkers Weekly Salary is: $ "<<WeeklySalary<<endl;
            break;
                                     
    default: cout<<"Employee does not exists."<<endl;break;        
    }
    
    cout<<"\n\nPress any key and ENTER to EXIT";
    
    char response;
    cin>> response;
    
    return 0;
}    

//this is the complete program... what im going to do is to convert the nested ifs to switch..
commented: No [code] blocks... +0

Glad you figured it out, but if you wrap it in [code] ...code blocks... [/code] it'll be easier to read. I think I mentioned this to you yesterday. You've been around long enough, you should know...

Also, I don't see a loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.