By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,837 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

How to calculate and print out the gross pay of 7 employees

P: 1
I need help, I am a beginner in C++ programming.
I have been given an assignment and I tried several times but cant do it and need help

this is the question and what I have done so far:

/*
Q1. Develop a C++ program that will determine the gross pay for each of several employees.
The company pays “straight-time” for the first 30 hours worked by each employee and pays
“time-and-a-half” (thus $10.5) for all hours worked in excess of 30 hours. You are given a list of
the employees of the company, the number of hours each employee worked last week and the
hourly rate of each employee. Your program should input this information for each employee
and should determine and display the employee's gross pay. The Basic rate for the 30 hours is
$500.
Employee Name Number of hours worked
Asamoah Billy 40
Vivian Lawrence 65
Kofi Nti 88
Nana Anane 70
Akua Jane 50
Papa Gyan 90
Cecelia Quaye 78
*/

#include <iostream>

using namespace std;

int main()
{
string EmployeeName[7]={"Asamoah Billy", "Vivian Lawrence", "Kofi Nti", "Nana Anane", "Akua Jane", "Papa Gyan", "Cecelia Quaye"};
int Number_of_hours_worked;
float overtime;
int work_limit;
double salary;
double Gross_Pay;


work_limit=30;
salary= 500;
overtime= 10.5;
Gross_Pay=(salary + overtime);

EmployeeName=Asamoah Billy;
Number_of_hours_worked=40;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Vivian Lawrence;
Number_of_hours_worked=65;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Kofi Nti;
Number_of_hours_worked=88;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Nana Anane;
Number_of_hours_worked=70;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Akua Jane;
Number_of_hours_worked=50;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Papa Gyan;
Number_of_hours_worked=90;
if (work_limit>30){Gross_Pay = salary + overtime};

EmployeeName=Cecelia Quaye;
Number_of_hours_worked=78;
if (work_limit>30){Gross_Pay = salary + overtime};

cout << "Employee Name\t" << "Number of hours worked\t" << "Gross Pay" <<endl;

return;


}
Nov 21 '17 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
You have an array of strings for the employee names but you are using the same Number_of_hours_worked for each employee. You need a Number_of_hours_worked for each employee.

Your solution here is to have an array of employees. Each employee is an object of a class (or struct):

Expand|Select|Wrap|Line Numbers
  1. Employee emp[7];
  2.  
where:

Expand|Select|Wrap|Line Numbers
  1. class Employee
  2. {
  3.    private:
  4.      string name;
  5.      int Number_of_hours_worked;
  6. etc...
  7. };
  8.  
You can use a struct instead of a class since I don't know how far along you are with classes.
Nov 21 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.