The code below is for my assignment it works i just want to make sure i did this correct any advice is wanted. Also one thing that is bugging me see basepay well if the base pay is 133.20 it chops off the 0 and only displays 133.2 why iv tried all kinds of things ....


Thank you for your time!

//Ryan Summey
//Overtime Pay Structures
//04/20/2010


#include <iostream>
#include <string>

using namespace std;

struct Employee {
	void DisplayEmployInformation();
	string employeeName; 
	int hours, overtime_hours;
	double wage, basepay;
	double overtime_pay, overtime_extra;
	double iIndividualSalary; 
	void otCalc(string EmployeeName, int hours, double wage);
};



int main()
{
    
	Employee Employee0;
	 system("cls");
	 cout << "\nWelcome to the Employee Pay Center\n\n";

	 
 
	cout << "\n\nEnter the employee name = ";
	cin >> Employee0.employeeName;
	cout << "Enter the hours worked  = ";
	cin >> Employee0.hours;
	cout << "Enter his or her hourly wage = ";
	cin >> Employee0.wage;



Employee0.otCalc(Employee0.employeeName, Employee0.hours, Employee0.wage);

}


void Employee::otCalc(std::string EmployeeName, int hours, double wage){

  basepay = 0.00;
  overtime_hours = 0;
  overtime_pay = 0.00;
  overtime_extra = 0.00;
  iIndividualSalary = 0.00;

  


	  if (hours > 40) 
	  {

	    basepay = 40 * wage;
        overtime_hours = hours - 40;
		overtime_pay = wage * 1.5;
		overtime_extra = overtime_hours * overtime_pay;
		iIndividualSalary = overtime_extra + basepay;
		

       DisplayEmployInformation ();
	  }

  else{
	    basepay = hours * wage;
		iIndividualSalary = basepay; 

		DisplayEmployInformation ();
  }
}

void Employee::DisplayEmployInformation()
{

       
        cout << "\n\n";
		cout << "Employee Name ............. = " << employeeName << endl;
		cout << "Base Pay .................. = " << basepay << endl; 
		cout << "Hours in Overtime ......... = " << overtime_hours << endl;
		cout << "Overtime Pay Amout......... = " << overtime_extra << endl;
        cout << "Total Pay ................. = " << iIndividualSalary << endl;
	   
		system("PAUSE"); 
		return;
}

Haven't gone through the code yet. But I think you will need to set the precision of cout .to attain that result.

cout.precision(2);
cout << "Base Pay .................. = " << basepay << endl;

Thank you for your time it really means alot!

this is my out put with cout.percision(2);

Welcome to the Employee Pay Center

Enter the employee name = Ryan
Enter the hours worked = 44
Enter his or her hourly wage = 3.33


Employee Name ............. = Ryan
Base Pay .................. = 1.3e+002
Hours in Overtime ......... = 4
Overtime Pay Amout......... = 20
Total Pay ................. = 1.5e+002
Press any key to continue . . .

Actually I think it's cout<< fixed << setprecision(2)
and make sure you include iomanip

Brilliant THANK YOU THANK YOU!

cout.setf(ios::fixed);
cout.precision(2);
cout<< "Base Pay : "<<basepay

This would do the same. sorry didn't mention about Setf.

awesome thank you for your help!

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.