473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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
1 1915
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

1
by: Don Leverton | last post by:
Hi Folks, I *can* calculate the Gross Profit Percentage where both the Cost and SellPrice are known, using the formula: (SellPrice - Cost) / SellPrice = GPP eg ($24.92 - $14.95) / $24.92 =...
7
by: habsy | last post by:
The below are the question given; Please help. (Payroll) Write a program that reads the following information and prints payroll statements in show message dialog box. These are the...
5
by: NareshN | last post by:
Hi, I have weekly wise scheduled hours of each employee and no of days scheduled for each employee,now i need to calculate no of employees scheduled less than 24 hours,no of emp's scheduled b/w...
3
by: badandy71 | last post by:
i'm writing a java payroll program for class. I am at the end of the program but I can not figure out how to average the gross/net pay of all employees entered. I know that I must create an array...
3
by: ItsKemb | last post by:
Develop a program that will determine the gross pay for each of several employees. The company pays "straight time" for the first 40 hours worked by each employee and pays "time-and-a-half" for all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.