I think that the only function that needs fixing is my ComputeHourlyPay function. Could somebody take a look and help me out here.

//Name: Nick Auffarth
//Class: CS 140 Section 003
//Assignment: p03
//Date: October 15, 2007

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

const char OFFICE = 'A';
const char MANUFACTURING = 'B';
const char QUIT = 'Q';

const int WAGON_LINE = 1;
const int SLED_LINE = 2;
const int ROLLER_SKATE_LINE = 3;

const double OVERTIME_SCALE = 1.5;

const double WAGON_BONUS = 1.10;
const double SLED_BONUS = 1.25;
const double ROLLER_SKATE_BONUS = 1.5;


void ProgrammerNote();
char ChooseDepartmentMenu();
void ProcessOfficeWorker();
double ComputeHourlyPay(double hoursWorked, double hourlyRate);
void DisplayPay(string empName, double regularPay, double overtimePay, double bonusPay, double totalPay);
void ProcessManufacturingWorker();
int ChooseProductionLineMenu();


void main()
{
	
	ProgrammerNote();
	char choice;
	
	do
	{
	choice = ChooseDepartmentMenu();	
	
	switch(choice)
	{
		case 'a':
		case 'A':
			{
				ProcessOfficeWorker();									

			}break;
		case 'b':
		case 'B':
			{
				ProcessManufacturingWorker();
			}
			break;
		case 'q':
		case 'Q':
			{
			}
			break;
	}
	}
	while(choice != 'q' && choice != 'Q');

		
	}

				



void ProgrammerNote()
{
	cout << "Programmed by Nick Auffarth" << endl << endl;
	
}

char ChooseDepartmentMenu()
{
	char choice;
	
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(6) << " " <<"Department Menu" << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(5) << " " <<"[A] Office" << endl;
	cout << setw(5) << " " <<"[B] Manufacturing" << endl;
	cout << setw(5) << " " <<"[Q] Quit" << endl << endl;
	
	do
	{
	cout << setw(5) << " " <<"Enter Your Selection [A|B|Q]: ";
	cin >> choice;
	cout << endl << endl;
	
	if(choice != 'a' && choice != 'A' && choice != 'b' && choice != 'B' && choice != 'q' && choice != 'Q')
		{
			cerr << setw(5) << " " << "Error: Invalid Choice. Please Try Again." << endl << endl;
		}

	}while (choice != 'a' && choice != 'A' && choice != 'b' && choice != 'B' && choice != 'q' && choice != 'Q');
	
	
	
	
		
	return (choice);
	
}



double ComputeHourlyPay(double hoursWorked, double hourlyRate)
{
	double regularPay = 0;
	double overtimePay;
	double totalPay;

	cout << fixed 
		 << setprecision(2);
		
	if(hoursWorked <= 40)
	{
		regularPay = ComputeHourlyPay(hoursWorked, hourlyRate);
	}
	if(hoursWorked > 40)
	{
		overtimePay = ComputeHourlyPay(hoursWorked - 40, hourlyRate * OVERTIME_SCALE);
	}
	totalPay = regularPay + overtimePay;
	return (totalPay);
}


void DisplayPay(string empName, double regularPay, double overtimePay, double bonusPay, double totalPay)
{
	

	cout << fixed 
		 << setprecision(2);

	cout << "Employee Name" << setw(5) << ":" << empName << endl;
	cout << "Regular" << setw(13) << ": $" << regularPay << endl;
	cout << "Overtime" << setw(12) << ": $" << overtimePay << endl;
	cout << "Bonus" << setw(15) << ": $" << bonusPay << endl;
	cout << "Total" << setw(15) << ": $" << totalPay << endl;
}
void ProcessOfficeWorker()
{
	string empName;
	double hoursWorked;
	double hourlyRate;
	double regularPay = 0;
	double overtimePay = 0;
	double bonusPay = 0;
	double totalPay = 0;

	cout << "Enter employee's last name: ";
	cin >> empName;
	cout << "Enter hours worked: ";
	cin >> hoursWorked;
	cout << "Enter hourly rate: ";
	cin >> hourlyRate;
	cout << endl << endl;

	ComputeHourlyPay(hoursWorked, hourlyRate);
	
	DisplayPay(empName, regularPay, overtimePay, 0, totalPay);



	
	
}



void ProcessManufacturingWorker()
{
	string empName;
	double hoursWorked;
	double hourlyRate;
	double regularPay = 0;
	double overtimePay = 0;
	double bonusPay = 0;
	double totalPay = 0;


	cout << "Enter employee's last name: ";
	cin >> empName;
	cout << "Enter hours worked: ";
	cin >> hoursWorked;
	cout << "Enter hourly rate: ";
	cin >> hourlyRate;
	
	ComputeHourlyPay(hoursWorked, hourlyRate);

	ChooseProductionLineMenu();

	DisplayPay(empName, regularPay, overtimePay, bonusPay, totalPay);

}

int ChooseProductionLineMenu()
{
	int ans;
	double numItems;
	double bonusPay;
	
	cout << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(6) << " " <<"Manufacturing Menu" << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(5) << " " <<"[1] Wagons" << endl;
	cout << setw(5) << " " <<"[2] Sleds" << endl;
	cout << setw(5) << " " <<"[3] Roller Skates" << endl << endl;

	do
	{
	cout << setw(5) << " " <<"Enter Your Selection [1-3]: ";
	cin >> ans;	

	if(ans != 1 && ans != 2 && ans != 3)
			{
				cerr << setw(5) << " " << "Error: Invalid Choice. Please try again." << endl << endl;
			}
	}while(ans != 1 && ans != 2 && ans != 3);
	
	

	cout << endl << endl;
	cout << "How many items were made? ";
	cin >> numItems;
	cout << endl;

	switch(ans)
	{
	case 1:
		{
			bonusPay = numItems * WAGON_BONUS;
		}break;
	case 2:
		{
			bonusPay = numItems * SLED_BONUS;
		}break;
	case 3:
		{
			bonusPay = numItems * ROLLER_SKATE_BONUS;
		}break;
	}




	
	

	return (ans);



	
}

Recommended Answers

All 7 Replies

you don't need the recursion. First compute the normal pay. Then if over 40 hours compute overtime pay. Here OVERTIME_SCALE would have to be redefined as 0.5

double ComputeHourlyPay(double hoursWorked, double hourlyRate)
{
	double regularPay = 0;
	double overtimePay = 0;
	double totalPay;

	cout << fixed 
		 << setprecision(2);
		
	regularPay = hoursWorked * hourlyRate;
	if(hoursWorked > 40)
	{
  	    overtimePay = (hoursWorked - 40) *  (hourlyRate * OVERTIME_SCALE);
	}
	totalPay = regularPay + overtimePay;
	return (totalPay);
}

Ok I see, thanks for that. Also thanks for correcting my code tags.

For some reason though when I input the hoursWorked and hourlyPay my out put is all $0.00. Why is that I can't seem to figure it out.

because ProcessOfficeWorker() knows nothing about the values of variables set by ComputeHourlyPay(). You need to pass more parameters to ComputeHourlyPay() by reference.

Here's my code now. For some reason I'm still getting zeros even though I added more parameters to ComputeHourlyPay function.

//Name: Nick Auffarth
//Class: CS 140 Section 003
//Assignment: p03
//Date: October 15, 2007

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

const char OFFICE = 'A';
const char MANUFACTURING = 'B';
const char QUIT = 'Q';

const int WAGON_LINE = 1;
const int SLED_LINE = 2;
const int ROLLER_SKATE_LINE = 3;

const double OVERTIME_SCALE = 1.5;

const double WAGON_BONUS = 1.10;
const double SLED_BONUS = 1.25;
const double ROLLER_SKATE_BONUS = 1.5;


void ProgrammerNote();
char ChooseDepartmentMenu();
void ProcessOfficeWorker();
double ComputeHourlyPay(double hoursWorked, double hourlyRate, double regularPay, double overtimePay, double totalPay);
void DisplayPay(string empName, double regularPay, double overtimePay, double bonusPay, double totalPay);
void ProcessManufacturingWorker();
int ChooseProductionLineMenu();


void main()
{
	
	ProgrammerNote();
	char choice;
	
	do
	{
	choice = ChooseDepartmentMenu();	
	
	switch(choice)
	{
		case 'a':
		case 'A':
			{
				ProcessOfficeWorker();									

			}break;
		case 'b':
		case 'B':
			{
				ProcessManufacturingWorker();
			}
			break;
		case 'q':
		case 'Q':
			{
			}
			break;
	}
	}
	while(choice != 'q' && choice != 'Q');

		
	}

				

// Name:		ProgrammerNote()
// Desc:		Outputs who programmed the program
// Args:		No arguments
//  Ret:		No value returned

void ProgrammerNote()
{
	cout << "Programmed by Nick Auffarth" << endl << endl;
	
}
// Name:		char ChooseDepartmentMenu()
// Desc:		Displays a menu with the departments and a quit option.
			//  Returns the user's menu choice. Validates their selection
			//  and repeatedly gives an error message if an invalid choice is made.
// Args:		<char> <> - <description>
//				<type><argn> - <description>
//  Ret:		Returns(choice)

char ChooseDepartmentMenu()
{
	char choice;
	
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(6) << " " <<"Department Menu" << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(5) << " " <<"[A] Office" << endl;
	cout << setw(5) << " " <<"[B] Manufacturing" << endl;
	cout << setw(5) << " " <<"[Q] Quit" << endl << endl;
	
	do
	{
	cout << setw(5) << " " <<"Enter Your Selection [A|B|Q]: ";
	cin >> choice;
	cout << endl << endl;
	
	if(choice != 'a' && choice != 'A' && choice != 'b' && choice != 'B' && choice != 'q' && choice != 'Q')
		{
			cerr << setw(5) << " " << "Error: Invalid Choice. Please Try Again." << endl << endl;
		}

	}while (choice != 'a' && choice != 'A' && choice != 'b' && choice != 'B' && choice != 'q' && choice != 'Q');
	
	
	
	
		
	return (choice);
	
}



double ComputeHourlyPay(double hoursWorked, double hourlyRate, double regularPay, double overtimePay, double totalPay)
{
	cout << fixed 
	<< setprecision(2);

	regularPay = hoursWorked * hourlyRate;
	
	if(hoursWorked > 40)
	{
		overtimePay = (hoursWorked - 40) * (hourlyRate * OVERTIME_SCALE);
	}
	totalPay = regularPay + overtimePay;
	return (totalPay);
}


void DisplayPay(string empName, double regularPay, double overtimePay, double bonusPay, double totalPay)
{
	double hoursWorked = 0;
	double hourlyRate = 0;
	cout << fixed 
		 << setprecision(2);
		
	cout << "Employee Name" << setw(6) << ": " << empName << endl;
	cout << "Regular" << setw(13) << ": $" << regularPay << endl;
	cout << "Overtime" << setw(12) << ": $" << overtimePay << endl;
	cout << "Bonus" << setw(15) << ": $" << bonusPay << endl;
	cout << "Total" << setw(15) << ": $" << totalPay << endl;
}
void ProcessOfficeWorker()
{
	string empName;
	double hoursWorked = 0;
	double hourlyRate = 0;
	double regularPay = 0;
	double overtimePay = 0;
	double bonusPay = 0;
	double totalPay = 0;
	

	cout << "Enter employee's last name: ";
	cin >> empName;
	cout << "Enter hours worked: ";
	cin >> hoursWorked;
	cout << "Enter hourly rate: ";
	cin >> hourlyRate;
	cout << endl << endl;

	ComputeHourlyPay(hoursWorked,hourlyRate, regularPay, overtimePay, totalPay);
	DisplayPay(empName, regularPay, overtimePay, bonusPay, totalPay);

	



	
	
}



void ProcessManufacturingWorker()
{
	string empName;
	double hoursWorked;
	double hourlyRate = 0;
	double regularPay = 0;
	double overtimePay = 0;
	double bonusPay = 0;
	double totalPay = 0;


	cout << "Enter employee's last name: ";
	cin >> empName;
	cout << "Enter hours worked: ";
	cin >> hoursWorked;
	cout << "Enter hourly rate: ";
	cin >> hourlyRate;
	
	ComputeHourlyPay(hoursWorked, hourlyRate, regularPay, overtimePay, totalPay);

	ChooseProductionLineMenu();

	DisplayPay(empName, regularPay, overtimePay, bonusPay, totalPay);

}

int ChooseProductionLineMenu()
{
	int ans;
	double numItems;
	double bonusPay;
	
	cout << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(6) << " " <<"Manufacturing Menu" << endl;
	cout << setw(5) << " " <<"-------------------"<< endl;
	cout << setw(5) << " " <<"[1] Wagons" << endl;
	cout << setw(5) << " " <<"[2] Sleds" << endl;
	cout << setw(5) << " " <<"[3] Roller Skates" << endl << endl;

	do
	{
	cout << setw(5) << " " <<"Enter Your Selection [1-3]: ";
	cin >> ans;	

	if(ans != 1 && ans != 2 && ans != 3)
			{
				cerr << setw(5) << " " << "Error: Invalid Choice. Please try again." << endl << endl;
			}
	}while(ans != 1 && ans != 2 && ans != 3);
	
	

	cout << endl << endl;
	cout << "How many items were made? ";
	cin >> numItems;
	cout << endl;

	switch(ans)
	{
	case 1:
		{
			bonusPay = numItems * WAGON_BONUS;
		}break;
	case 2:
		{
			bonusPay = numItems * SLED_BONUS;
		}break;
	case 3:
		{
			bonusPay = numItems * ROLLER_SKATE_BONUS;
		}break;
	}




	
	

	return (ans);



	
}

line 126: you did not specify the parameters are passed by reference -- you have to use the & operator to do that

double ComputeHourlyPay(double hoursWorked, double hourlyRate, double& regularPay, double& overtimePay, double& totalPay)

Still all zeros....I swear this is the assignment from hell. I put the & operator in Line 126 but then i got errors for overloaded function. So I put the & operator in the function before main. Still all zeros.

I wonder if I'm getting all zeros since all of my pay variables are set equal to zero. I did that so I wouldn't get an uninitialized variable error.

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.