calculate overtime

when i enter 61 in Number of hours, it should give me 316 but it gives me 312.
if u can please help me as im unable to solve it. thanx




#include<iostream>
using namespace std;
int main()
{
float overtime,h;
cout<<"Q1****Overtime Payment****"<<endl<<endl;
cout<<"Number of Hours = ";cin>>h;

if (h<35)
overtime=0;
else if ((h-35)<=60 )
overtime=(h-35)*8*1.5;
else if (h>60)
overtime=(h-60)*8*2+25*8*1.5;
cout<<"Overtime = "<<overtime<<endl<<endl;
system("PAUSE");
return 0;

}

1
2
else if ((h-35)<=60 )
overtime=(h-35)*8*1.5;


312 is correct. (61-35)*8*1.5 equals 312.
but for 61 hours, it shud give me. 316
koz the first 35 hrs give zero, the next 25 hrs give 300 and the remaining give 16

here is the question,
A worker is paid at the hourly rate of Rs8 per hour for the first 35 hours worked. Thereafter, overtime is paid at 1.5 times the hourly rate for the next 25 hours worked and 2 times the hourly rate for further hours worked. Write a program to input the number of hours worked per week and output the overtime paid.
You've simply got your algorithm wrong.

Get number of hours.
Subtract 35.
if number is zero or less than zero, overtime is zero.
if number is 25 or less, overtime equals number times 1.5 * 8
if number is 26 or more, overtime equals (25*1.5*8 + (number-25)*2*8)
Topic archived. No new replies allowed.