payroll. hope you'll help me

The payroll manager at central computers wants a program that calculates and displays the grosspay for each of the company's employees. It also should calculate and display the total gross pay. The pay roll manager will enter the number of hours the employee worked and his or her pay rate. Employees working more than 40 hours should receive one half of the hours over 40. Use a value returning function to determine an employee's gross pay. Use a different value- returning function to accumulate the total grosspay. The program should display the total gross pay only after the payroll managet has finished entering the data for all the employee's. Use a sentinel value to end the program. Here what i have done so far. I dont know if this is correct please check here. I use my phone to post this. Codepad.org/s6kkuzem

closed account (SECMoG1T)
One more step and you're done.

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
#include <iostream>

using namespace std;

double getTotalPay (double hoursWorked, double payRate);
int main ()
{
	/*
	* The payroll manager will enter the number of hours
	* the employee worked and his or her pay rate
	* 
	* Use a sentinel value to end the program
	* sentinel is 0
	*/
	double hoursWorked, payRate, gross;
	gross = 0;
	cout << "hours worked : (enter 0 to terminate) ";
	cin >> hoursWorked;
	
	
	
	while ( hoursWorked > 0 )
	{
		cout << "pay rate : ";
		cin >> payRate;
		
		gross += 
		getTotalPay (hoursWorked, payRate);
		
		cout << "hours worked : (enter 0 to terminate) ";
		cin >> hoursWorked;
	}
	
	/*
	 * The program should display the total gross pay 
	 * only after the payroll manager has finished entering 
	 * the date for all the employees
	 */ 
	cout << "gross pay : " << gross << endl;
	
}

double getTotalPay (double hoursWorked, double payRate)
{
	/*
	* Employees working more than 40 hours should 
	* receive hourly payment for hours above 40 hours 
	* as one and half hours payrate
	*/ 
	double grossPay;
	if ( hoursWorked > 40 )
	{
		int extraHours = 40 - hoursWorked;
		int extraPayRate = 1.5 * payRate;
		grossPay = ( 40 * payRate ) + ( extraHours * extraPayRate );
	}
	else
	{
		grossPay = hoursWorked * payRate;
	}
	return grossPay;
}


your requirements

1. calculates and displays grosspay for each. -1/2 only calculations
2. calculate and display the total gross pay.                             -ok
3. more than 40 hours should receive one half of the hours over 40            -?
      int extraHours = 40 - hoursWorked;- error
      int extraPayRate = 1.5 * payRate; - perfect
4. Use a value returning function to determine an employee's gross pay. - ok
5. Use a different value- returning function to accumulate the total grosspay. -not found
6.display the total //// finished entering the data for all the employee's.         - ok
7. Use a sentinel value to end the program                              -ok


But overall yh got the idea , maybe i can show you an example that should give you the idea on how you should achieve your requirements.

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
struct worker///i'll use these struct to hold each person's details.
{
    string name;
    int hours=0;
    double total_pay=0.0;
};

///this fuction calcu;ates a persons total pay ie : person.total=person.hrs*pay/hr and also 
//handles hrs>40 and then  returns the person object after calculations
worker get_gross_for_each( worker& person);

double get_total_gross(const std::vector<worker>& myvec);
///all worker objects returned by the previous function are stored in a vector
/// and then after calculations the vector is passed into these fuction which will
///sum all person.total_pay values together and retutn that value, probably in a
///loop
 
void print(const std::vector<worker>& vect);
///this function will print the content of the previous vector in a loop 
///cout<<person.name<<" "<<person.totalpay<<endl;, you can also use a plain loop
///you dont require this function anyway.

///NOTE> define those functions and that's all.

//example
int main()
{
  worker temp;
  std::vector<worker> my_vec;
  std::cout<<"Company payroll system\n";

  cout<<"enter worker's name followed by hours worked\n enter name as null and hours as 0 to quit\n: ";
  cin>>temp.name>>temp.hours;

  while(temp.name!="null"&&temp.hours>0)
  {
    worker person=get_gross_for_each(temp);
    my_vec.push_back(person);
    std::cout<<"\nNext worker : ";
    cin>>temp.name>>temp.hours;
  }

  double total_gross=get_total_gross(my_vec);
  print(my_vec);
  std::cout<<"\tThe gross payment is : "<<total_gross<<"$$";


}



the above program should be a good example of probably how your program should look like.
Thanks it works :D when i runnmy first program it just stuck at the pay rate -.- thank you so much. :) working on your example.
Topic archived. No new replies allowed.