Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 10-21-2003, 07:32 PM   #1 (permalink)
.pakmon.
Guest
 
Posts: n/a
omfg... well, i may need help just understanding this problem...

Well, i have this problem on one homework assignment. I don't need help on the code as I'm breaking it down step by step, BUT, i'm just wondering if I'm overlooking this problem.

here it is, btw, this is C++

*********************
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and "time-and-a-half"--1.5 times their hourly wage - for overtime hours worked), commisioned workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers ( who receive a fixed amount of money per item for each of the items they produce--each pieceworker in this company works on only one type of item).

Write a program to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code:

Managers have paycode 1, hourly workers have 2, commission workers have 3 and pieceworkers have code 4.

Use a switch to compute each employee's pay according to that employee's paycode. Within the switch prompt the user (i.e., the payroll clerk) to enter the appropriate facts your program needs to calculate each employee's pay according to that employee's paycode.
*********************

Well basically i broke it down in bits. I created if statements for the Hourly worker to display his pay regardless if he worked overtime or not. I coded the commisione worker. Salary = Whatever, and so on.

Then I see the finalized line.

How do I call the code within the switch function? WTF! Isn't the switch function a way to do things if you don't want to use the if/else statements? Do I just paste my code within a case then break? Or am I just overlooking something here because this prick wants too much from a n00b?

I can post my code if need be.
  Reply With Quote
Old 10-22-2003, 07:39 PM   #2 (permalink)
palin
Code Monkey
 
palin's Avatar
 
Join Date: Jan 2003
Posts: 57
palin is on a distinguished road
Code:
switch(paycode){
   case 1: //calculate pay
           break;
   case 2: //calculate pay
           break;
   default: std::cout << "you entered an                  in correct pay type";
           break;

}
The switch will execute any code between the case 1: and the break; statements.


This may have changed but yeah it used to be implemented as a series of if/else statements. Java does it as a jump table but they may have changed the way the compilier works. in any case its a cleaner neater looking way of doing instead of if else statements.
palin is offline   Reply With Quote
Old 10-23-2003, 05:04 PM   #3 (permalink)
.pakmon.
Guest
 
Posts: n/a
woot, i got it...

thanks man... works great.
just in case anyone needs this or i made a mistake in my math.

Code:
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name = " ";
	int total = 0;
	int paycode = 0;
	double salary = 0.0;
	double payRate = 0.0;
	double hourlyRate = 0.0;
	double commissionRate = 0.0;
	double fixedRate = 0.0;
	int hoursWorked = 0.0;
	double itemsProduced = 0.0;
	double overtime = 0.0;
	double sales = 0.0;

	
	cout << "Employee Name: ";
	cin >> name;
	cout << "\nSelect an Employee Status/Paycode for this employee:\n \n 1.Manager \n 2.Hourly Worker \n 3.Commisioned Worker \n 4.Piece Worker? \n \n(Enter 1, 2, 3, or 4 where applicable): ";
	cin >> paycode;


	switch (paycode) 
	{
	case 1:	cout << "What is the weekly salary for this employee?: ";
			cin >> salary;
			cout << " " << name << " has made $ " << salary << " this week." << endl;
			break;
	
	case 2:	cout << "Hourly rate for this employee: " << endl;
			cin >> payRate;
			cout << "Hours worked this week: " << endl;
			cin >> hoursWorked;
			if (hoursWorked > 40)
			{
				total = (40*payRate);
				overtime = total + ((hoursWorked % 10) * (payRate + (payRate / 2)));
				cout << " " << name << " has made a total of $ " << overtime << " for the week." << endl;
			}
			else
			{
				total = payRate * hoursWorked;
				cout << " " << name << " has made a total of $ " << total << " for the week." << endl;
			}
			break;
			
	case 3:	cout << "Enter the number of sales: ";
			cin >> sales;
			cout << "Enter your salary: ";
			cin >> salary;

			commissionRate = 250 + (sales / 7.5);
			total = commissionRate + salary;
			cout << " " << name << " has made $ " << total << " this week." << endl;
			break;

	case 4:	cout << "Enter the number of items produced this week: ";
			cin >> itemsProduced;
			cout << "Enter the cost per item: ";
			cin >> payRate;
			total = itemsProduced * payRate;
			cout << " " << name << " has made $ " << total << " for the week." << endl;
			break;

	default:  cout << "Error" << endl;
	} //end of switch
	
	return 0;
}
  Reply With Quote
Old 01-08-2004, 08:44 AM   #4 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
I only have one problem with your code. Why are you taking the hoursWorked % 10 for hourly people who work overtime? For an 80 hour week (God forbid) one would only be paid for 40 hours. 80 % 10 = 0; Should this not be:

Code:
... (hoursWorked - 40) * ...
Just wondering,
- Ted
__________________
while(1) fork();
ender is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
structure problem Goshi Standard C, C++ 5 04-21-2003 12:19 AM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM
PHP / JS problem bdl HTML, XML, Javascript, AJAX 2 03-13-2003 08:53 AM
Problem printing, please help me laurence10 Java 0 03-11-2003 04:26 PM


All times are GMT -8. The time now is 05:23 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting