Not Getting the right output

Page 1 of 1

1 Replies - 243 Views - Last Post: 11 January 2012 - 08:10 PM Rate Topic: -----

#1 tray2475  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Not Getting the right output

Posted 11 January 2012 - 07:38 PM

I am working on my final project and I am having a problem getting the right outcome.

Here is what I am supposed to get:

Welcome to the Employee Pay Center

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

Enter the employee name = Mary
Enter the hours worked = 33
Enter his or her hourly wage = 2.22

Enter the employee name = Mark
Enter the hours worked = 29
Enter his or her hourly wage = 2.22

Employee Name ............. = John
Base Pay .................. = 133.20
Hours in Overtime ......... = 4
Overtime Pay Amount........ = 19.98
Total Pay ................. = 153.18

Employee Name ............. = Mary
Base Pay .................. = 73.26
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 73.26

Employee Name ............. = Mark
Base Pay .................. = 64.38
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 64.38

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Total Employee Salaries ..... = 290.82
%%%% Total Employee Hours ........ = 106
%%%% Total Overtime Hours......... = 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The problem is I only get the outcome for employee John and nothing eles. Any help that points me in the right direction would be very helpfull

Here is my code:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//
//class declaration section
//
class employeeclass
{
public:
	void implementcalculations (string employeename, int hours, double wage);
	void displayemployeeinformation (void);
	void addsomethingup (employeeclass, employeeclass, employeeclass);
	string employeename;
	int hours;
	float wage;
	float basepay;
	int overtime_hours;
	float overtime_pay;
	float overtime_extra;
	float itotal_salaries;
	float iIndividualsalary;
	int itotal_hours;
	int itotal_overtimehours;
};

int main()
{
	system ("cls");

	cout << "\nWelcome to the Employee Pay Center\n\n";

/*
use this section to define your objects. You will have one object per employee. You have only three employees.
The format is your class name and your object name.
*/
employeeclass emp1;
employeeclass emp2;
employeeclass emp3;

/*
Here you will prompt for the first employee's information.
Prompt the employee name, hours worked, and the hourly wage. For each piece of information, you will update the appropriate class member defined above.
Example of prompts
Enter the employee name     =
Enter the hours worked      =
Enter his/her hourly wage   =

*/
	cout << "Enter the first employee's name       =";
	cin >> emp1.employeename;
	system("cls");
	cout << "\nEnter hours worked                  =";
	cin >> emp1.hours;
	system("cls");
	cout << "\nEnter his/her hourly wage           =";
	cin >> emp1.wage;
	system("cls");
/*
Here you will prompt for the second employee's information.
Prompt the employee name, hours worked, and the hourly wage. For each piece of information, you will update the appropriate class member defined above.
Example of prompts
Enter the employee name     =
Enter the hours worked      =
Enter his/her hourly wage   =

*/
	cout << "Enter the Second employee's name       =";
	cin >> emp2.employeename;
	system("cls");
	cout << "\nEnter hours worked                  =";
	cin >> emp2.hours;
	system("cls");
	cout << "\nEnter his/her hourly wage           =";
	cin >> emp2.wage;
	system("cls");

/*
Here you will prompt for the third employee's information.
Prompt the employee name, hours worked, and the hourly wage. For each piece of information, you will update the appropriate class member defined above.
Example of prompts
Enter the employee name     =
Enter the hours worked      =
Enter his/her hourly wage   =

*/
	cout << "Enter the Third employee's name       =";
	cin >> emp3.employeename;
	system("cls");
	cout << "\nEnter hours worked                  =";
	cin >> emp3.hours;
	system("cls");
	cout << "\nEnter his/her hourly wage           =";
	cin >> emp3.wage;
	system("cls");

/*
Here you will implement a function call to implement the employ calcuations for each object defined above.  You will do this for each of the three employees or objects.
The format for this step is the following:
 [(object name.function name(objectname.name, objectname.hours, objectname.wage)] ;
*/
	cout << endl;
	emp1.implementcalculations(emp1.employeename, emp1.hours, emp1.wage);
	emp2.implementcalculations(emp2.employeename, emp2.hours, emp2.wage);
	emp3.implementcalculations(emp3.employeename, emp3.hours, emp3.wage);

/*
This section you will send all three objects to a function that will add up the the following information:
- Total Employee Salaries 
- Total Employee Hours
- Total Overtime Hours

The format for this function is the following:
-	Define a new object.
-	Implement function call [objectname.functionname(object name 1, object name 2, object name 3)]
*/

	
} // End Main Function


void employeeclass::implementcalculations (string employeename, int hours, double wage){
//Initialize overtime variables
overtime_hours=0;
overtime_pay=0;
overtime_extra=0;

	if (hours > 40) 
{

/* 
This section is for the basic calculations for calculating overtime pay.
-	base pay = 40 hours times the hourly wage
-	overtime hours = hours worked  40
-	overtime pay = hourly wage * 1.5
-	overtime extra pay over 40 = overtime hours * overtime pay
-	salary = overtime money over 40 hours + your base pay
*/
	basepay = 40 * wage;
	overtime_hours = hours - 40;
	overtime_pay = wage * 1.5;
	overtime_extra = overtime_hours * overtime_pay;
	iIndividualsalary = overtime_extra + basepay;

/*
Implement function call to output the employee information. Function is defined below.
*/
displayemployeeinformation();

	}  //if (hours > 40)
	else (hours < 40);
{
/*
Here you are going to calculate the hours less than 40 hours.
-   Your base pay is your hours worked times your wage
-   Salary = your base pay
*/
	basepay = hours * wage;
	iIndividualsalary = basepay;

/*
Implement fucntion call output the employee information. Function is defined below.
*/

	 // End of the else

	displayemployeeinformation();
}

} // Ende primary function

void employeeclass::displayemployeeinformation ()
{
// This function displays all the employee output information

/* 
This is your cout statements to display the employee information:
Employee Name ............. = 
Base Pay .................. = 
Hours in Overtime ......... = 
Overtime Pay Amount........ = 
Total Pay ................. = 
*/

	cout << "Employee Name......................" << setw(15) << employeename << endl;
	cout << "Base Pay..........................." << setw(15) << basepay << endl;
	cout << "Hours in Overtime.................." << setw(15) << overtime_hours << endl;
	cout << "Overtime Pay Amount................" << setw(15) << overtime_extra << endl;
	cout << "Total Pay.........................." << setw(15) << iIndividualsalary << endl;
}// End of Display Employee Information

void employeeclass::addsomethingup (employeeclass emp1, employeeclass emp2, employeeclass emp3)
{
	// Adds two objects of class employee passed as
	// function arguments and saves them as the calling object's data values

/*
Add the total hours for object 1, 2, and 3.
Add the salaries for each object.
Add the total overtime hours.
*/
	itotal_hours = emp1.hours + emp2.hours + emp3.hours;
	itotal_salaries = emp1.iIndividualsalary + emp2.iIndividualsalary + emp3.iIndividualsalary;
	itotal_overtimehours = emp1.overtime_hours +emp2.overtime_hours + emp3.overtime_hours;
/*
Then display the information below.  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Total Employee Salaries ..... = 576.43
%%%% Total Employee Hours ........ = 108
%%%% Total Overtime Hours......... = 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

	for (int i=0; i<55; i++)
		cout << "%";
	cout << endl;
	cout << "%%%%%%%%%%%%%%%% Employee Summary Data %%%%%%%%%%%%%%%%" << endl;
	for (int i=0; i<55; i++)
		cout << "%";
	cout << endl;
	cout << "%%%% Total Employee Salaries.............=" << setw(15) << itotal_salaries << endl;
	cout << "%%%% Total Employee Hours................=" << setw(15) << itotal_hours << endl;
	cout << "%%%% Total Overtime Hours................=" << setw(15) << itotal_overtimehours << endl;
	for (int i=0; i<55; i++)
		cout << "%";
	cout << endl;
	for (int i=0; i<55; i++)
		cout << "%";
	cout << endl;
} // End of function


Is This A Good Question/Topic? 0
  • +

Replies To: Not Getting the right output

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Not Getting the right output

Posted 11 January 2012 - 08:10 PM

please don't open duplicate topics

*closed*
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1