Payroll calculations error stopping @40

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 3226 Views - Last Post: 18 November 2012 - 07:01 PM Rate Topic: -----

#1 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Payroll calculations error stopping @40

Posted 16 November 2012 - 12:51 PM

// 2it218 tester.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>

using namespace std;

//Global Declarations of Variables
double iovertime_hours=0,iwage=0,iovertime_pay=0,iovertime_extra=0,ihours=0;

string cname ;

int main ()
{
	//Enter Employee Information
	cout << "\n\nEnter the employee name = ";
	cin >> cname ;
	cout << "Enter the hours worked  = ";
	cin >> ihours;
	cout << "Enter his or her hourly wage = ";
	cin >> iwage; 
	
	// Determine if hours are greater than 40 
	if (ihours <40) 
	{
		//Do Calculations
		iovertime_hours=(40-ihours);
		iovertime_pay=(ihours-40)*iwage*1.5;
		iovertime_extra=iovertime_hours*iwage*1.5;

		// Display Employee Details
		
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << ihours-40*iwage << endl; 
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_pay*iovertime_hours*iwage*1.5 << endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(ihours-40)*(iwage)+(iovertime_hours*iovertime_pay) << endl;
	}    
	else // Else hours are less than 40 hours
	{
		cout << "\n\n";
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << ihours*iwage << endl ;
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_extra +(ihours-40)*iwage*1.5<< endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(iovertime_hours * iwage*1.5)+(ihours*iwage) << endl;
		_getch();
	} // End of the primary if statement 

} //End of Int Main


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 16 November 2012 - 03:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Payroll calculations error stopping @40

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5465
  • View blog
  • Posts: 11,740
  • Joined: 02-June 10

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 02:29 PM

Please edit your post and wrap code tags around your code.
Its posted everywhere. Everyone does it if they don't want their thread deleted.
:code:

Attached Image

You also need to actually describe your problem.
The title of the thread is not enough.

What line does the execution stop on?
What is the full error message you receive?
Was This Post Helpful? 0
  • +
  • -

#3 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 02:44 PM

okay here I go again.
the program is to create a payroll program to calculate base pay and overtime pay. My program does not stop base pay at 40 hours is goes full length the code here is my code (wrapped)
// 2it218 tester.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>

using namespace std;

//Global Declarations of Variables
double iovertime_hours=0,iwage=0,iovertime_pay=0,iovertime_extra=0,ihours=0;

string cname ;

int main ()
{
	//Enter Employee Information
	cout << "\n\nEnter the employee name = ";
	cin >> cname ;
	cout << "Enter the hours worked  = ";
	cin >> ihours;
	cout << "Enter his or her hourly wage = ";
	cin >> iwage; 
	
	// Determine if hours are greater than 40 
	if (ihours <40) 
	{
		//Do Calculations
		iovertime_hours=(ihours-40);
		iovertime_pay=(40-ihours)*iwage*1.5;
		iovertime_extra=iovertime_hours*iwage*1.5;

		// Display Employee Details
		
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << ihours-40*iwage << endl; 
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_pay*iovertime_hours*iwage*1.5 << endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(ihours-40)*(iwage)+(iovertime_hours*iovertime_pay) << endl;
	}    
	else // Else hours are less than 40 hours
	{
		cout << "\n\n";
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << ihours*iwage << endl ;
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_extra +(ihours-40)*iwage*1.5<< endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(iovertime_hours * iwage*1.5)+(ihours*iwage) << endl;
		_getch();
	} // End of the primary if statement 

} //End of Int Main


Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5465
  • View blog
  • Posts: 11,740
  • Joined: 02-June 10

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 03:05 PM

Quote

My program does not stop base pay at 40 hours is goes full length

I'm sorry; I don't understand that.

YOu do have some problems with your basic math though.
Do you understand the order of operations for basic math?

  • Everything is parenthesis
  • Exponents
  • Multiplcation/Dividion
  • Addition/Subtraction


Which means your formulas like this:
ihours-40*iwage

Will do 40*iwage first, then subtract that result from ihours second.

I always surround each operation with parenthesis just to be safe

(ihours-40)*iwage
Was This Post Helpful? 0
  • +
  • -

#5 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 03:22 PM

what it is spouse to do Sample output:



Enter the Employee Name = Mary

Enter the hours worked = 43

Enter his or her hourly wage = 3.00



Employee Name ............. = Mary

Base Pay .................. = 120

Hours in Overtime ......... = 3

Overtime Pay Amount........ = 13.5

Total Pay.................. = 133.5


what it is doing
is base pay=129
total pay =129
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,474
  • Joined: 23-August 08

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 03:40 PM

If you're doing your calculations here:

//Do Calculations
iovertime_hours=(ihours-40);
iovertime_pay=(40-ihours)*iwage*1.5;
iovertime_extra=iovertime_hours*iwage*1.5;


Why would you do them again when you're printing?

cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << ihours-40*iwage << endl; 
cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_pay*iovertime_hours*iwage*1.5 << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(ihours-40)*(iwage)+(iovertime_hours*iovertime_pay) << endl;

Was This Post Helpful? 2
  • +
  • -

#7 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 04:04 PM

it seems to be the only way to get the program to work. The assignment as issued is :Use the code in Appendix B for this assignment.

Correct the compile errors to arrive at the following output.



Sample output:



Enter the Employee Name = Mary

Enter the hours worked = 43

Enter his or her hourly wage = 3.00



Employee Name ............. = Mary

Base Pay .................. = 120

Hours in Overtime ......... = 3

Overtime Pay Amount........ = 13.5

Total Pay.................. = 133.5

the code example we were given to use:
Associate Program Material
Appendix B

Use the following code to complete your Overtime Pay Compile Errors assignment.

#include <io>
#include <string>
#include <iomanip>
#include <conio.h>

using namespace std;

//Global Declarations of Variables
double iovertime_hours=0, iovertime pay=0, iovertime_extra=0;
int ihours, iwage ;
string cname ;

int main ()
{
	//Enter Employee Information
	cout << "\n\nEnter the employee name = ";
	cin >> cname ;
	cout << "Enter the hours worked  = "
	cin >> ihours;
	cout << "Enter his or her hourly wage = "
	cin >> iwage 

	// Determine if hours are greater than 40 
	if (ihours < 40) 
	{
		//Do Calculations
		iovertime_hours=ihours+40;
		iovertime_pay=iwage-1.5 ;
		iovertime_extra=iovertime_hours*iovertime_pay;

		/ Display Employee Details
		cout >> "\n\n";
		cout << "Employee Name ............. = ' << cname << endl ;
		cout << "Base Pay .................. = " << iwage*40 << endl 
		cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
		cout << Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
	}    
	else // Else hours are less than 40 hours
	{
		cout << "\n\n";
		cout << "Employee Name ............. = " << cname << endl ;
		cout << Base Pay .................. = " << iwage*40 << endl ;
		cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
	} // End of the primary if statement 

} //End of Int Main




the more I mess with it the more the math is wrong. current code looks like this.:
// 2it218 tester.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>

using namespace std;

//Global Declarations of Variables
double iovertime_hours=0,iwage=0,iovertime_pay=0,iovertime_extra=0,ihours=0;

string cname ;

int main ()
{
	//Enter Employee Information
	cout << "\n\nEnter the employee name = ";
	cin >> cname ;
	cout << "Enter the hours worked  = ";
	cin >> ihours;
	cout << "Enter his or her hourly wage = ";
	cin >> iwage; 
	
	// Determine if hours are greater than 40 
	if (ihours <40) 
	{
		//Do Calculations
		iovertime_hours=(ihours-40);
		iovertime_pay=(40-ihours)*iwage*1.5;
		iovertime_extra=iovertime_hours*iwage*1.5;

		// Display Employee Details
		
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << (ihours-40)*iwage << endl; 
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_pay*iovertime_hours*iwage*1.5 << endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(ihours-40)*(iwage)+(iovertime_hours*iovertime_pay) << endl;
	}    
	else // Else hours are less than 40 hours
	{
		cout << "\n\n";
		cout << "Employee Name ............. = " << cname << endl ;
		cout << "Base Pay .................. = " << ihours*iwage << endl ;
		cout << "Hours in Overtime ......... = " << iovertime_hours-(40-ihours) << endl ;
		cout << "Overtime Pay Amout......... = " << iovertime_extra +(ihours-40)*iwage*1.5<< endl ;
		cout << "Total Pay ................. = " << iovertime_extra+(iovertime_hours * iwage*1.5)+(ihours*iwage) << endl;
		_getch();
	} // End of the primary if statement 

} //End of Int Main


Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 05:28 PM

Part of your problem is in this line:
		cout << "Base Pay .................. = " << ihours*iwage << endl ;



Please tell me what Base Pay means to you?

Please tell us what your program in currently outputting with the given input.


Also I recommend you stop using global variables, this is a very bad habit to get in to. At this point since you only have one function, main() just put all the declarations into this one function.

Also why do you have two "main() functions? The _tmain(), would be the same as main() if you are using a Windows compiler, I recommend you get rid of that function and just use main for now.

Jim

This post has been edited by jimblumberg: 16 November 2012 - 05:31 PM

Was This Post Helpful? 2
  • +
  • -

#9 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 06:33 PM

When I run the program with mary working 43 hours and a hourly wage of 3
I get mary's base pay=$129
hours in over time 3
overtime pay amount 13.5
total pay =129

Base pay is the amount of pay up to 40 hours. We are using Microsoft Visual 2010 express
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5465
  • View blog
  • Posts: 11,740
  • Joined: 02-June 10

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 06:45 PM

Let me be VERY frank.

The problems here aren't so much about confusing syntax as they are about sloppy workmanship.
Duplicate code, bad variable names, no planning.

This is basically what one should expect when you sit down and start banging on a keyboard without actually planning first. I don't care if its a couple peices of paper or a whiteboard, but you should plan.

This is really simply 8th grade math. Work it out on paper first. How do you calculate a paycheck? One step at a time

TotalHours = {UserInput}
HourlyRate = {UserInput}
OvertimeHours = TotalHours - Regular hours
RegularPay = HourlyRate * Regular hours
OvertimePay = (1.5 * HourlyRate) * OvertimeHours
TotalPay = RegularPay + OvertimePay


My suggestion is that you have so much crap in this project that you not try to fix it.
Just start a new solution. You've learned from version 1. Now make a clean version 2.
Was This Post Helpful? 2
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 07:19 PM

Quote

Base pay is the amount of pay up to 40 hours.


So with the input provided you get 129 for base pay. What is 129 divided by the wages?

Jim
Was This Post Helpful? 1
  • +
  • -

#12 mkjt88  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 11-February 11

Re: Payroll calculations error stopping @40

Posted 16 November 2012 - 08:41 PM

Hi RamO.. I actually coded this program a few weeks ago myself. I think your over thinking it a bit.. To many unnecessary variables seems to be a problem to me. It makes it to hard to keep track of what your doing. You don't really need the normal and overtime variables for hours and pay. I started out with mine about the same way you were heading and by the time I finished I cut my code down to 31 lines and rid of 3 variables. I'll post what I did so you can see how I solved my problems with it and I think you could rethink how to improve yours from a few lines of mine. Let me know if it helps at all or if you have any questions.. I'm glad you posted this also I forgot about this code and I remembered now I want to try to add the function to take out a percent of taxes for the final payments.

#include <iostream>
using namespace std;

int main ()
{
	string ename;
	double hours;
	double wages;
	
	// Get Employee Info
	cout << "\nEnter Employee Name: ";
	cin >> ename;
	cout << ename << "'s hourly wages: ";
	cin >> wages;
	cout << "Total weekly hours worked: ";
	cin >> hours;
	
	// Calculate Pay
	if (hours <= 40) {
		cout << "\n" << ename << "'s weekly base pay is $" << wages * hours;
	}
	
	else if (hours > 40) {
		double otpay = (hours - 40) * (wages * 1.5);
		cout << "\n" << ename << "'s weekly base pay = $" << wages * 40 << endl;
		cout << ename << "'s weekly overtime pay = $" << otpay << endl;
		cout << ename <<"'s total weekly pay = $" << (wages * 40) + otpay << endl;
	}
	
    return 0;
}

This post has been edited by mkjt88: 16 November 2012 - 08:42 PM

Was This Post Helpful? 1
  • +
  • -

#13 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5465
  • View blog
  • Posts: 11,740
  • Joined: 02-June 10

Re: Payroll calculations error stopping @40

Posted 17 November 2012 - 07:47 AM

mkjt88 WE DO NOT PROVIDE FINISHED CODE FOR HOMEWORK ASSIGNMENTS.

The student doesn't learn and grow if we do their homework for them.

Please don't do this again. It is more work to teach, and lead someone in the right direction and point out a couple mistakes in their math - but they will get something out of that.

Think along these line:
Give me a program and I eat for a day, teach me to program and I eat for a lifetime.
Was This Post Helpful? 0
  • +
  • -

#14 mkjt88  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 11-February 11

Re: Payroll calculations error stopping @40

Posted 17 November 2012 - 09:07 AM

Sorry about that I read the first 4-5 posts then just scrolled down to see if it has been solved and seen nothing about this being an assignment. It won't happen again and I cannot edit my post again to remove.. Dunno if the damage is already done...
Was This Post Helpful? 0
  • +
  • -

#15 RamOinRenO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-May 12

Re: Payroll calculations error stopping @40

Posted 17 November 2012 - 05:47 PM

View PosttlhIn`toq, on 16 November 2012 - 06:45 PM, said:

Let me be VERY frank.

The problems here aren't so much about confusing syntax as they are about sloppy workmanship.
Duplicate code, bad variable names, no planning.

This is basically what one should expect when you sit down and start banging on a keyboard without actually planning first. I don't care if its a couple peices of paper or a whiteboard, but you should plan.

This is really simply 8th grade math. Work it out on paper first. How do you calculate a paycheck? One step at a time

TotalHours = {UserInput}
HourlyRate = {UserInput}
OvertimeHours = TotalHours - Regular hours
RegularPay = HourlyRate * Regular hours
OvertimePay = (1.5 * HourlyRate) * OvertimeHours
TotalPay = RegularPay + OvertimePay


My suggestion is that you have so much crap in this project that you not try to fix it.
Just start a new solution. You've learned from version 1. Now make a clean version 2.

This is the work the teacher gave she said to fix the errors and compile this is only my second assignment for this class. Every time we ask the teacher a question her response has been the same its part of the assignment figure it out. The text book is teaching us how to use Microsoft Visual 2010 not C++ which is the class INTRO to C++. Math since 1994 (when I was in the eight grade changed) and between 1993-1998 I was a patent at University of Chicago Hospitals for a brain tumor, Copd. So most of the stuff everyone else learned I got my assignments delivered to the hospitable. Now the code in the assignment was all pre-wrote by the teacher all I did was do what Visual Basic said to do to fix it. Between base pay and total pay is were I am lost on why. I took the double math out and it pulled up blank just the "lines with in these marks showed up" Thought this was a community web site for learning but being barked at when no one is actually teaching.... peace
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3