On Wed, Feb 27, 2008 at 10:02 AM, burtonics <[EMAIL PROTECTED]> wrote:
> We are on Chapter5 Repetitions and Loop Statements
>  Repetitions in programs|Counting Loops and the while statement
>  Computing a Sum or a product loop|the For Statement|conditional Loops
>  Loop Design|Nested Loops| Do-While statment and Flag-Controlled Loops|
>
>  The book we are using is Problem Solving and Program Design In C
>  Fourth Edition. Which even the Professor said it is not a very good
>  book for newbies and he is trying to get them to change it. I have to
>  agree.

Looking at it, it hasn't covered either structs or arrays in great
detail - I'll assume no structs and just use arrays. I"m also assuming
here that you want to input all the employees first, then do the
calculations and output, rather than doing the calculations and output
after each employee entry.

See at the end for a much simpler version that doesn't even use
arrays. I'm unsure as to which your tutor is expecting, but I rather
suspect it's the latter (since the former uses a function that returns
a value which isn't covered until chapter 6,) but since I spent time
on the former before realising it, I leave it here anyway:



I present below the process you should be going through when reading
the requirements with a view to producing code.

>  Write a program to process weekly employee time cards for all
>  employees of an organization.

#define MAX_EMPLOYEES 10 /* or however many you need to handle*/

> Each employee will have three data
>  items: an identification number,

int emp_id[MAX_EMPLOYEES];

> the hourly wage rate,

double emp_rate[MAX_EMPLOYEES];

>and the number  of hours worked during a given week.

double emp_hours[MAX_EMPLOYEES]; /* This assumes that the program will
only handle one week per execution run */

> Each employee is to be paid time
>  and a half for all hours worked over 40.

#define OVERTIME_LIMIT 40

> A tax amount of 3.625 percent of gross salary will be deducted.

#define TAX_RATE 3.625

>  The program output should show the
>  employee's number and net pay.

double emp_net[MAX_EMPLOYEES];

> Display the total payroll and the
>  average amount paid at the end of the run.

double total_pay;
int employee_count;

Right - that's the 'global stuff' out of the way that you're going to
need - tidied up, I re-present it here:

#define MAX_EMPLOYEES 10 /* or however many you need to handle*/
#define OVERTIME_LIMIT 40
#define TAX_RATE 3.625

int emp_id[MAX_EMPLOYEES];
double emp_rate[MAX_EMPLOYEES];
double emp_hours[MAX_EMPLOYEES]; /* This assumes that the program will
only handle one week per execution run */
double emp_net[MAX_EMPLOYEES];
double total_pay = 0.0;
int employee_count = 0;

You are now going to need some functions to deal with input,
calculations, and output

#include <stdio.h>

/* Input */
void  input_employee(int emp_number){
  // input emp_id[emp_number];
  // input emp_rate[emp_number];
  // input emp_hours[emp_number];
}

/* calculation */
double  process_employee(int emp_number){
 // use OVERTIME_LIMIT, TAX_RATE and emp_hours[emp_number] to
calculate emp_net[emp_number]
 // return emp_net[] to be used in calling function to totalise payroll
}

/* some of output */
void output_employee(int emp_number){
 // output emp_id[] and emp_net[]
}

int main(void){
   int current_employee = 0;

   while (employee_count < MAX_EMPLOYEES){
      input_employee(employee_count); // Note that this starts at
employee number 0, not 1.
      // increment employee_count
   }

   for (current_employee = 0; current_employee < employee_count;
current_employee++){
      total_pay = total_pay + process_employee(current_employee);
   }

   for (current_employee = 0; current_employee < employee_count;
current_employee++){
      process_employee(current_employee);
   }

   // print out total_pay and work out average pay using total_pay and
employee_count. Note that employee_count is zero based, and not one
based when doing this.

   return 0;
}

=============================
=============================
=============================

Alternatively, if you don't want arrays at all and can do
input/processing/output each time an employee is entered, a much
simplified version follows:

#define OVERTIME_LIMIT 40
#define TAX_RATE 3.625

#include <stdio.h>

int main(void){
   double total_pay;
   int employee_count = 0;

  while(/* more employees */){
      // input employer id, rate and hours
      // calculate net pay and add to total_pay
      // output employer id and net pay
      // increment employee_count
   }
   // output total_pay and average pay
  return 0;
}



-- 
PJH

http://shabbleland.myminicity.com

Reply via email to