Hello,

I know i'm suppose to ask programming questions but i'm stuck on how to do it in the first place, the question is:

You are given 4 information-gross pay, number of extra hours worked, the hourly pay rate, and the income tax rate. Calculate the overtime payment:

Overtime payment = extra hours worked * hourly pay rate - deductions
Deduction = social security + income tax + union dues totaling 5.00
Social security = 8.5% of the gross pay
Income tax = rate of tax * gross pay

I finish the code but the final answer which is 'overtime payment' i'm getting a negative value. I'm not sure if I went wrong in input or what, but I need some help on what the input should be. Thanks.

#include<iostream>
using namespace std;

double social(double security);
int uniondue = 5;

int main()
{
	double gross,hours,tax;
	double overtime=0;
	double deduction=0;
	int rate;

	cout<<"****Xstyle Company****"<<endl;
	cout<<"Gross Pay: ";
	cin>>gross;
	cout<<"Number of extra hours worked: ";
	cin>>hours;
	cout<<"Hourly pay rate: ";
	cin>>rate;
	cout<<"Income tax rate(%): ";
	cin>>tax;
	tax = (tax/100)*gross;

	cout<<tax<<endl;
	deduction = social(gross) + tax + uniondue;

	cout<<deduction<<endl;
	overtime = (hours * rate) - deduction;
	cout<<overtime;

return 0;
}

double social(double security)
{
	security = (0.085) * security;
	return (security);
}

code posted

Code & calculation looks fine.

NOTE: uniondue should be defined as a static const. (optional)

If deduction is greater than hours * rate, your overtime will be negative.

Can you post your inputs?

Code & calculation looks fine.

NOTE: uniondue should be defined as a static const. (optional)

If deduction is greater than hours * rate, your overtime will be negative.

Can you post your inputs?

gross pay = 5000
tax rate = 4%
overtime hours = 25
hourly pay = 20

This works out to a negative overtime , right?

Try giving a hourly pay of 50.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.