Hello everyone.
I'm new to DaniWeb and new to programming with t C++

i have been working on a problem for several days now and I think i may have the code correct except i'm getting compiling errors related to my if..else statements in the GetGrossPay function. I've tried moving the brackets every which way but i still get the same errors.
I dont know if its the IF statements that are the problem or if its the braces that are teh problem. If possible i would like to get some feedback on this.

I've remarked out the printoutput function definition as it was generating garbage on the screen. why would that happen?

#include <iomanip>				//precompiler directives
#include <iostream>
#include <string>

using namespace std;			



void GetEmployeeData (string &EmpNamef, int &EmpIdf,float &hrsWorkedf,float &hrlyRatef);

void ComputeGrossPay (float hrsWorkedf, float hrlyRatef, float &grossPayf, float &regPay, float &oTPay);

//void PrintOutput(&EmpNamef,&EmpIdf,&hrsWorkedf,&hrlyRatef,&grossPayf);


void main()	
{																//start of main functio

//declare local identifiers

	string EmpName;
	int EmpId;
	float hrsWorked,hrlyRate,regPay,oTPay;
	float grossPay; 


	

GetEmployeeData (EmpName,EmpId,hrsWorked,hrlyRate);				//call function to get employee data

	
ComputeGrossPay (hrsWorked,hrlyRate,grossPay,regPay,oTPay);      //call function to calculate pay

	
//void PrintOutput(empName,EmpIdf,hrsWorkedf,hrlyRatef,grossPayf);	//call function to print output


return;
}


//start function to get employee data

void GetEmployeeData (string &EmpNamef, int &EmpIdf,float &hrsWorkedf,float &hrlyRatef)

{
	string fname, lname;
	int empIdf;
//	float hrlyRate, hrsWorked;

cout<<"Please enter the employees first and last name separated by a space: \n";
cin>>fname>>lname;
cout<<"Enter the employee ID number:  \n";
cin>>empIdf;
//cout<<"Enter the employee's hourly wage:  \n";
//cin>>hrlyRate;
//cout<<"Enter the number of hours worked for the previous work week:  \n";
//cin>>hrsWorked;
	EmpNamef= fname + ' ' + lname;

}	//END function to get employee data




//BEGIN function to compute gross pay

void ComputeGrossPay (float hrsWorkedf, float hrlyRatef, float &grossPayf, float &regPayf, float &oTPayf)

{

	float hrsWorked,hrlyRate,grossPay,regPay,oTPay;
	const float REGWEEK = 40.00;
	hrlyRate = 0;
	hrsWorked = 0;
	


	cout<<"Enter the number of hours worked: \n";
	cin>>hrsWorked;
		

	if ((hrsWorked <= REGWEEK) && (hrsWorked !=0))
	
	{
		
	cout<<"Enter the hourly rate for this employee:  \n";
	cin>>hrlyRate;
		grossPay = hrsWorked * hrlyRate;
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"This employee is not eligible for OT.  The gross pay is:  "<<grossPay<<endl;
			
	
		else if(hrsWorked > REGWEEK)
			
	cout<<"enter hourly rate:  \n";
	cin>>hrlyRate;
		
			oTPay = ((hrlyRate * 1.5) * (hrsWorked - 40));
			regPay = (REGWEEK * hrlyRate);
			grossPay = (regPay + oTPay);

		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"This employee is eligible for OT.  The gross pay is:  $"<<grossPay<<endl;
	
		else 
	}
		cout<<"Hourly employees who do not work can not receive a pay check."<<endl;
	
	

}	//end of compute gross pay function



//void PrintOutput(empName,&EmpIdf,&hrsWorkedf,&hrlyRatef,&grossPayf)
//{

//	string lNamef;
//	int EmpIdf;
//	float hrsWorkedf,hrlyRatef;
//	float grossPayf; 
//empName,EmpIdf,hrsWorkedf,hrlyRatef,grossPayf

//cout<<"\n\n"<<setw(40)<<"Employee Payroll Program";
//cout<<endl<<endl;
//cout<<"\tName\tEmployee ID\t Hours Worked\t Hourly Rate \t Gross Pay \n\n";



}
Member Avatar for iamthwee

When you say you've tried moving the brackets either way, that sounds like to me you don't know what you're doing.

If you don't know what you're doing how do expect to fix this. Trial and error?

//BEGIN function to compute gross pay

void ComputeGrossPay (float hrsWorkedf, float hrlyRatef, float &grossPayf, float &regPayf, float &oTPayf)

{

float hrsWorked,hrlyRate,grossPay,regPay,oTPay;
const float REGWEEK = 40.00;
hrlyRate = 0;
hrsWorked = 0;

cout<<"Enter the number of hours worked: \n";
cin>>hrsWorked;


if ((hrsWorked <= REGWEEK) && (hrsWorked !=0))

{

cout<<"Enter the hourly rate for this employee: \n";
cin>>hrlyRate;
grossPay = hrsWorked * hrlyRate;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"This employee is not eligible for OT. The gross pay is: "<<grossPay<<endl;


else if(hrsWorked > REGWEEK)

cout<<"enter hourly rate: \n";
cin>>hrlyRate;

oTPay = ((hrlyRate * 1.5) * (hrsWorked - 40));
regPay = (REGWEEK * hrlyRate);
grossPay = (regPay + oTPay);

cout<<fixed<<showpoint<<setprecision(2);
cout<<"This employee is eligible for OT. The gross pay is: $"<<grossPay<<endl;

else
}
cout<<"Hourly employees who do not work can not receive a pay check."<<endl;

} //end of compute gross pay function
}

Yes, the fault was the if-else statement.
You missed some braces and did have the wrong one on 1 line.

Here is your ComputeGrossPay function fixed.

//BEGIN function to compute gross pay
void ComputeGrossPay (float hrsWorkedf, float hrlyRatef, float &grossPayf, float &regPayf, float &oTPayf)
{
	float hrsWorked,hrlyRate,grossPay,regPay,oTPay;
	const float REGWEEK = 40.00;
	hrlyRate = 0;
	hrsWorked = 0;
	
	cout<<"Enter the number of hours worked: \n";
	cin>>hrsWorked;
			
	if ((hrsWorked <= REGWEEK) && (hrsWorked !=0))
	{
		
		cout<<"Enter the hourly rate for this employee:  \n";
		cin>>hrlyRate;
		grossPay = hrsWorked * hrlyRate;
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"This employee is not eligible for OT.  The gross pay is:  "<<grossPay<<endl;
	} // Missed this brace
	else if(hrsWorked > REGWEEK)
	{ // this brace too		
		cout<<"enter hourly rate:  \n";
		cin>>hrlyRate;
		
		oTPay = ((hrlyRate * 1.5) * (hrsWorked - 40));
		regPay = (REGWEEK * hrlyRate);
		grossPay = (regPay + oTPay);

		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"This employee is eligible for OT.  The gross pay is:  $"<<grossPay<<endl;
	} // <- this 1 too
	else 
	{  	// this brace was wrong, u had this } an end brace
        
		cout<<"Hourly employees who do not work can not receive a pay check."<<endl;
	} 	// this brace was forgotten
}	//end of compute gross pay function

no - as in i've tried what i believe is correct. and that woudl be putting braces around the compound statements. BUt alas that has not resolved my issue so that leaves me to try tweaking it as if possibly i'm placing brackets in the incorrect way.

as i mentioned in my initial post i am NEW to c++

Member Avatar for iamthwee

what is your issue?

commented: flipped comment and not relevant -3

http://www.daniweb.com/forums/announcement8-3.html
In a survey of Daniweb, this link appeared 99.9% of the time - I wonder why?

Probably because all the noobs are impatient dolts who can't wait to get their post onto the web, and don't give a rats ass what the resulting mess looks like.

News flash - a lot of people just ignore badly formatted posts as a complete waste of time.

no - as in i've tried what i believe is correct. and that woudl be putting braces around the compound statements. BUt alas that has not resolved my issue so that leaves me to try tweaking it as if possibly i'm placing brackets in the incorrect way.

as i mentioned in my initial post i am NEW to c++

I gonna try your code later and see where the issue is.

ZXAn
Thank you for your feedback. I'm afraid that your bracket placement didnt work either. YOur change gave me the same result that i was originally getting

I tweaked/ simplified my code and came up wihth what seems to work.

OTRate = (hrRate + (hrRate/(float) 2));
OTPay = OTRate * (hrsWorked - 40);
GrossPay = RegPay + OTPay;

if (hrsWorked <=40)

{
	RegPay = (hrsWorked * hrRate);
	cout<<fixed<<showpoint<<setprecision(2);
	cout<<"This employee is not eligible for overtime pay.  The gross pay is $"<<RegPay<<endl;
}
		
else
	((hrsWorked - 40) * OTRate);
	RegPay = (40 * hrRate);
	GrossPay = (RegPay + OTPay);
	cout<<OTRate<<endl;
	cout<<OTPay<<endl;

	cout<<"This employee is eligible for overtime pay.\n";
	cout<<"The gross pay is $"<<GrossPay<<endl;
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.