The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.

how do I do an if statement when > 80 hours = .5 ( time and a half ) else < 80 = 0

Then you woudl have somthing like

double OverTime;

double Hours;

// set hours.

if (Hours > 80)

Overtime = 0.5;

else

Overtime = 0;

Let me know if you have any questions.

Is it :

if(Current_time-Givven_tim

retcode = 0.5

else

retcode = 0

endif

?????

please tell me what i'm doing wrong.

//variable

double oT = 0;

// if

if (hoursWorked > 80) oT = 0.5;

else oT = 0;

// calculate

grossPay = hoursWorked * rate * oT;

Got U,

What U need is this:

float HoursWorked,GrossPay;

GrossPay=HoursWorked*Salar

if (HoursWorked > 80)

GrossPay+=((HoursWorked-80

(SalaryPerHour*0.5));

Have Fun

grossPay = hoursWorked * rate * oT;

can't be right when oT is 0 or .5. if oT is 0, then the pay will be 0, becayse ou are multiplying by 0. So what you want instead is 1 and 1.5, like

double oT = 0;

if (hoursWorked > 80) oT = 1.5;

else oT = 1;

grossPay = hoursWorked * rate * oT;

here's what I have so far. Aslo I don't have any errors.void main ()

{

//Define Variables

char lastName[10];

char firstName[10];

double hoursWorked = 0;

double rate;

double deduction = .425;

double grossPay;

double netIncome;

//Enter Input Items

cout <<"Enter your last name: ";

cin >> lastName;

cout <<"Enter your first name: ";

cin >> firstName;

cout << "Enter hours worked: ";

cin >> hoursWorked;

cout << "Enter pay rate: ";

cin >> rate;

//If over 80 hours

if (hoursWorked > 80)

grossPay=((hoursWorked-80)

//Calculate pay and deductions

grossPay = hoursWorked * rate;

deduction = (deduction * grossPay);

netIncome = grossPay - deduction;

its a lot simpler than writing a multi-line if for such a simple calc.

grossPay = rate * (hoursWorked<=80 ? hoursWorked : (80+1.5*(hoursWorked-80));

which 'simplifies'to

grossPay = rate * (hoursWorked<=80 ? hoursWorked : 1.5*hoursWorked-40);

When a conditional loks like this .. its time to write it as a couple of statements for clarity - and remove the use of the constant '80' as much as possible.

double standardHours;

double overtimeHours;

const double maxStandardHours = 80.0

if (hoursWorked <= maxStandardHours) {

standardHours = hoursWorked;

overtimeHours = 0.0;

} else {

standardHours = maxStandardHours;

overtimeHours = hoursWorked-standardHours;

}

grossPay = rate * (standardHours + 1.5*overtimeHours);

There are many variations on this theme. eg..

const double maxStandardHours = 80.0

double standardHours = (hoursWorked <= maxStandardHours) hoursWorked : maxStandardHours;

double overtimeHours = hoursWorked-standardHours;

grossPay = rate * (standardHours + 1.5*overtimeHours);

Even though there are many more lines in code like this, the result is easier to read and maintain.

And you're less likely to make mistakes like I did earlier :-)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

if (hoursWorked > 80)

grossPay=((hoursWorked-80)

//Calculate pay and deductions

grossPay = hoursWorked * rate;

by this:

// Calculate base salary

grossPay = hoursWorked * rate;

// Calculate Overtime

if (hoursWorked > 80)

grossPay+=((hoursWorked-80