Need Help

closed account (y7p9z8AR)
My professor has placed an assignment for us to do.
i figured out some but not all. could i get some help?
what i have down below is what i have as of now but the assignment states.
The program will ask the owner (who is the user of your program) for the number of employees in the company. After the user enters the number of employees, your program needs to ask the user for the input of hours and salary (hourly rate) of each employee. For example, if the owner enters 3 employees, your program needs to loop 3 times and capture the number of hours and hourly rate for each employee. Your program will need to keep track of the sum of all the employee salaries and display it to the user once they finish entering the data. In other words, the owner of the company wants to know the grand total as to how much he or she will have to pay in salaries that week, including overtime.

If the user enters more than 40 hours your program should calculate the overtime pay. For example, if for the first employee the owner enters 42 hours and 10 for rate, this should calculate to $430.00 dollars. If the user enters 38 hours and 10 for the rate, this should calculate to $380.00
The hours need to be captured in decimal form. For example, 40 hours and 30 minutes, need to entered as 40.5
The pay rate needs to be captured in decimal form. For example, the owner can enter $10.25 for an employee who makes 10 dollars and 25 cents an hour.
Your program will output to the user the sum of all the salaries of the employees. Your program should display the grand total with a setprecision of 2
Your program needs to loop and ask the user if they want to start over

#include <iostream>
#include <iomanip>
using namespace std;

int main (){

int numEmployees;
double numHours,
hourlyRate,
totalSales = 0.0,
employeeSalaries;
char doAgain;

do {

cout << "How many employees do you have? ";
cin >> numEmployees;

for (int num = 1; num <= numEmployees; num++)
{
cout << "\nEnter the hours for employee " << num << ": ";
cin >> numHours;
employeeSalaries = numHours * hourlyRate;
cout << "\nEnter the pay rate for employee " << num << ": ";
cin >> hourlyRate;
}

totalSales = employeeSalaries;

cout << fixed << showpoint << setprecision(2);
cout << "\nThe total for salaries you need to pay this week is " << totalSales << endl;

cout << "\nDo you want to start over? (Y/N) ";
cin >> doAgain;
} while (doAgain == 'Y' || doAgain == 'y');

return 0;
}
So you need to store that data somewhere and you don't know the number of employees.
To me that sounds like you need to use a vector.

You can look it up better than I can explain, and I don't see that in your code.
@SamuelAdams
To me that sounds like you need to use a vector.
Not at all. He only needs to store the total salary. Just a double if enough.

@OP
your code so far looks ok. However you should initialize all your variables at the begin of main.
Also you need to calculate the overtime of the employees, you can use constants for this.
1
2
const double DEFAULT_WAGE = 10.0;
const double OVERTIME_WAGE = 15.0;

What help do you need ?
Last edited on
Thomas is right. For some reason I thought you had to output each salary, vs all.
Topic archived. No new replies allowed.