#include "stdafx.h"
#using <mscorlib.dll>
	using namespace System;
#include <iostream>
	using namespace std;

int _tmain(){
	char payType;
	double payRate, salPay, sesTaxes, sesGross, totalTaxes=0, totalGross=0, aveGross, hours;
	int pwPieces, empCount=1, anotherRound, hourExempt;
	cout<<"Sam Lehman\nPayroll Output File\n"<<endl;

	while (true){	
		cout<<"Pay Type? (type S, P, or H)... ";
		cin>>payType;
		while (true){
			if (payType == 's' || payType == 'S' || payType == 'p' || payType == 'P' || payType == 'h' || payType == 'H'){
				break;
			}
			else{
				cout<<"Pay Type options can only be S, P, or H, Please try again: ";
				cin>>payType;
			}
		}

		if (payType == 'p' || payType == 'P'){
			cout<<"How Much do you get paid per piece? ";
			cin>>payRate;
			cout<<"How Many Pieces? ";
			cin>>pwPieces;

			sesGross = grossPay(pwPieces, payRate);
			sesTaxes = tax(sesGross);

			cout<<"Employee Pieces\tPay\tPay\tGross\tTaxes"<<endl;
			cout<<"Number\t Done\tRate\tPer\tPay\tPaid"<<endl;
			cout<<empCount<<"\t"<<pwPieces<<"\t"<<payRate<<"\t"<<sesGross<<"\t"<<sesTaxes;

		}
		else if(payType == 's' || payType == 'S'){
			cout<<"What is your salary per year? ";
			cin>>payRate;
			salPay = payRate/52;
			sesGross = grossPay(salPay);
		}
		else if(payType == 'H' || payType == 'h'){
			cout<<"How many hours did you work? ";
			cin>>hours;
			cout<<"How much do you get paid per hour? ";
			cin>>payRate;
			if (hours > 40){
				cout<<" Is this employee exempt? (press 1 for yes or 0 for no)\n  ";
				cin>>hourExempt;
			}
			sesGross = grossPay(hours, payRate, hourExempt);                                                                                                                                                       
		}
		else{
			cout<<"Some Type of Error Occured... Please run the program again."; return 0;
		}
		
		totalTaxes += sesTaxes;
		totalGross += sesGross;

		//process another?
		cout<<"\n\n Would you like to calculate another employee?\n    (press 1 for yes or 0 for no)\n  ";
		cin>>anotherRound;
		if (anotherRound == 0){
			aveGross = totalGross / empCount;
			cout<<"\n"<<empCount<<" employees were processed for a total gross pay of "<<totalGross<<" and an average gross pay of "<<aveGross<<" with "<<totalTaxes<<" taxes collected."<<endl;
			break;
		} 
		else{
			empCount++;
		}
	}
	return 0;
}

double grossPay(int piece, double pwRate){
	return piece * pwRate;
}
double grossPay(double salPay){
	return salPay;
}
double grossPay(double hHours, double hRate, int exempt){
	double otHours, otPay;
	if (exempt == 0){
		otHours = hHours - 40;
		otPay = otHours * hRate * 1.5;
	}
	else{
		otHours = hHours - 40;
		otPay = otHours * hRate * 1;
	}
	return ((hHours - otHours)*hRate) + otPay;
}
double tax(double grossPay){
	if (grossPay > 200.00 && grossPay <= 400.00){
		return (grossPay * .075);
	}
	else if (grossPay > 400.00){
		return (grossPay * .11);
	}
	else{
		return 0;
	}
}

this is what i get sofar,

here is the build log

------ Build started: Project: Program2, Configuration: Debug Win32 ------

Compiling...
Program2.cpp
Program2.cpp(32) : error C3861: 'grossPay': identifier not found, even with argument-dependent lookup
Program2.cpp(33) : error C3861: 'tax': identifier not found, even with argument-dependent lookup
Program2.cpp(44) : error C3861: 'grossPay': identifier not found, even with argument-dependent lookup
Program2.cpp(55) : error C3861: 'grossPay': identifier not found, even with argument-dependent lookup
Program2.cpp(79) : error C2365: 'grossPay' : redefinition; previous definition was a 'formerly unknown identifier'
Program2.cpp(82) : error C2365: 'grossPay' : redefinition; previous definition was a 'formerly unknown identifier'
Program2.cpp(85) : error C2365: 'grossPay' : redefinition; previous definition was a 'formerly unknown identifier'
Program2.cpp(97) : error C2365: 'tax' : redefinition; previous definition was a 'formerly unknown identifier'

Build log was saved at "file://m:\Visual Studio Projects\Program2\Program2\Debug\BuildLog.htm"
Program2 - 8 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped

anyone know what is wrong with the function calls?
i'm pretty new to C++.

nevermind, i put the functions before main and it worked..

i thought it was c++ was like java, where the funtions can be below main.

>i thought it was c++ was like java, where the funtions can be below main.
They can be if you prototype them.

1. You shouldn't use the same name for 3 functions. If you use the same name for muliple function definitions at the bottom of your code the C++ compiler will then attempt to match the inputs to the correct definition. Sure this will work but it is not good practice.

2. You shouldn't use the same variable names for the data being passed into the funciton call and the variable names being used in the definitions at the bottom.

3. Your middle definition of SesGross at the bottom simply returns what you are inputing. You could just make the assignment in main. That function isn't even necessary.

>Sure this will work but it is not good practice.
Why is that? They all do a similar job, they all take different arguments. This is a valid use of function overloading.

>You shouldn't use the same variable names for the data being passed into
>the funciton call and the variable names being used in the definitions at the bottom.
I know why you say this, but I don't entirely agree and I'm going to ask you to explain it in detail for the benefit of everyone else.

the reason i'm doing 3 different functions for grossPay is because the instructions for the assignments was to make a overloaded function called grossPay for each pay type.

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.