#include <iostream>
#include <string>
usingnamespace std;
constint Paid_per_hour = 100;
constint 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 )
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!
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);
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;
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";
}
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.