Extra hours (Please help!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
using namespace std;
const int Paid_per_hour = 100;
const int Paid_per_extra_hour = 150;
void welcome_messege();
string GetName(string FirstName,string LastName);
double GetHours(string FullName);
double ExtraHoursValue (int hours, int minutes);
//2 | P a g e
int main() {
welcome_messege();

string F,L,FullName;
FullName = GetName(F,L);

double Hours;
Hours = GetHours(FullName);

double total_salary = 150;
total_salary = Hours * Paid_per_hour;

int m,h;
char answer;
double ft;
cout<<"Is there any extra hours for" <<FullName <<"? y/n";
cin>>answer;
if (answer == 'y')
{ft=ExtraHoursValue(h,m);
cout << "\n " << FullName << "\'s total salary = " << "SR" << ft + total_salary <<"\n\n\n";
return ft;}
else
{ft=total_salary ;
cout << "\n " << FullName << "\'s total salary = " << "SR" << ft <<"\n\n\n";
return ft;}



system("pause");
return 0;
}
//functions

void welcome_messege(){
cout<<"\n\n======================================================";
cout<<"\n== Welcome to employee's salary calculating program ==";
cout<<"\n======================================================\n\n";
}
string GetName(string FirstName,string LastName){
string FN;
cout << " Employee's First Name: ";
cin >> FirstName;
cout << " Employee's last Name: ";
cin >> LastName;
FN = FirstName + " " + LastName;
return FN;
}
double GetHours(string FullName)
{
double TotalHours;
cout<<"\n --------------------------- \n";
cout <<" "<< FullName << "'s Weekly Hours = ";
cin>>TotalHours;
return TotalHours;
}

//
double ExtraHoursValue (int hours,int minutes){
double TEH;
	cout<<"Enter the total number of extra hours in term of hour<s> : ";
cin>>hours;
cout<<"Enter the total number of extra hours in term of minute<s> : ";
cin>>minutes;
TEH=((hours + minutes)/60)*Paid_per_extra_hour ;
return (TEH);
} 


When I press y the output shawn as

Enter the total number of extra hours in term of hour<s> : 
Enter the total number of extra hours in term of minute<s> :

FullName's total salary = total_salary ( here is the problem, it doesn't add ((hours + minutes)/60)*Paid_per_extra_hour to the total_salary )
Last edited on
I don't see the total_salary calculation in the program?


1
2
3
4
5
6

{ft=ExtraHoursValue(h,m);
cout << "\n " << FullName << "\'s total salary = " << "SR" << ft+total_salary <<"\n\n\n";
return ft;}

}
I have added the complete code.
and the total appear in the output screen without problems.
but it is not fair because final total for employee who have not extra hours= final total who have extra hours!

hope that is clear.
Last edited on
It looks like the overtime hours are not being paid. Total salary = TEH + total_salary

1
2
3
4
5
6

{ft=ExtraHoursValue(h,m);
cout << "\n " << FullName << "\'s total salary = " << "SR" << ft+total_salary <<"\n\n\n";
return ft;}

}



1
2
3
4
 cout<<"Enter the total number of extra hours in term of minute<s> : ";
cin>>minutes;
TEH=((hours + minutes)/60)*Paid_per_extra_hour ;     //Doesn't the hours need to be converted to minutes?
return (TEH);
Thank you leftcoast for replay

when I write

1
2
3
{ft=ExtraHoursValue(h,m);
cout << "\n " << FullName << "\'s total salary = " << "SR" << TEH+total_salary <<"\n\n\n";
return ft;}


it becomes error :(, because it is not declared in the main.

even if I use minutes instead of hours, how can I use TEH? without repeating this
1
2
3
4
cout<<"Enter the total number of extra hours in term of hour<s> : ";
cin>>hours;
cout<<"Enter the total number of extra hours in term of minute<s> : ";
cin>>minutes;
"
Last edited on
You need to move some of the statements around to the proper location for it to work. The code snippet below does calculate & add the OT properly. I added several check outputs. You could have other problems with you codes as I didn't check the whole program. Good luck!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (answer == 'y')
{
double TEH=0;
int othours=0;
int otminutes=0;

cout<<"Enter the total number of extra hours in term of hour<s> : ";
cin>>othours;
cout<<"Enter the total number of extra hours in term of minute<s> : ";
cin>>otminutes;

TEH=(othours + (otminutes/60))*Paid_per_extra_hour ;

cout<<"othours= "<<othours<<endl;     //check
cout<<"otminutes= "<<otminutes<<endl;     //check
cout<<"otrate= "<<Paid_per_extra_hour<<endl;     //check
cout<<"TEH= "<<TEH<<endl;     //check
cout << "\n " << FullName << "\'s total salary = " << "SR " << TEH + total_salary <<"\n\n\n";
}
Thank you so much!!
You're welcome! You might need to change the type on the otminutes & othours to float or double since the otminutes will be in a decimal format. I didn't test the program using the otminutes.
yeah it is easy step! I changed it before testing and it is work effectively!
All the best!
Topic archived. No new replies allowed.