I hva a program that i need help wtih. i made a program that will take the number of hours worked in a week and the number of dependents as inputs and then outputs the workers gross pay, each witholding amount, and the net take home pay per week. the person worked 34 hours out of 40 hours which is full.
9.50 and hour 6% withheld for state income tax, 14% withheld from federal income, 5% withheld from state income, $ 6 withheld for union dues. and if the person has three or more covered depedent, 10 additianal dollars is with held and the person has 2.
net take home pay should be 236.25
please not im still a beginner
heres my program
#include <iostream>
#using namespace std;
int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondue, dep, health; // gross income, overtime, social tax, federal tax, state tax, union due, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay. netpay; // overtime scoial federal state union dependents and health withholdings including netpay
// Loop to do everything
{
cout << "Hello Employee" << endl;
cout << "Enter hours you have worked: ";
cin >> regHours;
Please use the code tags when writing out your code. It makes it much easier to read.
What output are you getting from your program?
If the user enters "14" as input for a percentage, you need to divide 14 by 100 to obtain the decimal form of the percentage. Doing Number - 14xNumber will give you a negative number, but doing Number-0.14xNumber will give you the amount left after 14% is withheld.
over here im trying make the program calculate the number of hours the employee put which was overtime. the overtime hours was 1.5. but the employee has no overtime hours. but how to you make the program calculate the number of hours even if they dont have overtime
If overtime is any hours more than 40, you can try this:
1 2 3
//you could do this after gross = regHours * hourlyPay
if (regHours - 40 > 0)
gross += (regHours - 40) * otime * hourlyPay;
You multiple "otime" and "hourlyPay" together to get the hourly rate for overtime hours (if they get $10 per hour for regular hours, then they would get 1.5*10 = $15 per hour for any hours over 40 hours).
If the employee doesn't have any overtime (didn't work more than 40 hours), then it wouldn't get added to "gross". Any overtime would only get added if they worked more than 40 hours, and it would only calculate the overtime for the number of hours over 40 (if they worked 45 hours, they would get 5 hours of overtime, and 5 hours of overtime would get added to gross pay).
If you do that, then you can get rid of if (regHours<=40) because the amount will be withheld regardless of how many hours the employee worked. The calculations for how much will be withheld should always be calculated, regardless of how many hours were worked.
Right, but a bit more of an explanation:
At the top of your code you wrote this:
1 2
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondue, dep, health; // gross income, overtime, social tax, federal tax, state tax, union due, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay. netpay; // overtime scoial federal state union dependents and health withholdings including netpay
but you wrote this later on
unpay = gross - uniondues; //Union Dues
The two variable names for union dues don't match.
C++ will think they are different variables. Just change one of them (either remove the 's' from the first one, or add a 's' to the second one) so that they match.
theres one more error but i seem to not get it... can you ley me know what it is? it shows the error in the very last "{"
#include <iostream>
using namespace std;
int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondues, dep, health; // gross income, overtime, social tax, federal tax, state tax, union dues, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay, netpay; // overtime scoial federal state union dependents and health withholdings including netpay
// Loop to do everything
{
cout << "Hello Employee" << endl;
cout << "Enter hours you have worked: ";
cin >> regHours;
the program runs now but i still dont know the formula to add the overtime which is 1.5 hours if it exceeded fulltime hours which is 40. and a formula for number of dependents of if it exceeded 3 it woukd deduct 10$ from the gross pay
#include <iostream>
using namespace std;
int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondues, dep, health; // gross income, overtime, social tax, federal tax, state tax, union dues, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay, netpay; // overtime scoial federal state union dependents and health withholdings including netpay
// Loop to do everything
{
cout << "Hello Employee" << endl;
cout << "Enter hours you have worked: ";
cin >> regHours;
the program runs now but i still dont know the formula to add the overtime which is 1.5 hours if it exceeded fulltime hours which is 40. and a formula for number of dependents of if it exceeded 3 it woukd deduct 10$ from the gross pay
Can you do the calculations on your own with a calculator? Just write down every step you take in doing that and you have your algorithm.
If total hours were more than 40, you would find the difference between total hours and 40 to get overtime hours, then get the product of overtime hours and 1.5 to find overtime pay and add that to regular hours pay to get total pay..
The process for number of dependent deductions is almost identical to that. If total dependents are more than 3, find the difference between total dependents and 3, then (assuming you mean $10 per dependent) find the product of additional dependents and 10 and subtract that from the gross pay.