Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
Evil Grin C programming Pay Rate
Reply
Posted 2004-10-19, 12:09 PM
I need some help I am not sure how to program this. I am to post to be a employer that is interested in determining the pay an individual is to recieve. The number of hours and pay rate should be read in. If the hours are over the 40 the rate is "time and a half" for those hours over. Then I have to report the total earned amount, earned for regular hours and the amount earned for overtime hours. But this is what I have so far. The program is able to calculate the standard time but the overtime is incorrect. I want the user to be able to enter the hour and the rate. But I do not how to do that I only know how to assign it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <math.h>

#define MIN(x,y) ((x)<(y) ? (x) : (y))
#define MAX(x,y) ((x)>(y) ? (x) : (y))

#define MAX_EMPLOYEES 10
#define WAGE          6.75
#define STD_HOURS     40

#define MAX_BUFFER_SIZE 80

typedef struct {
  float std;
  float ot;
  float total;
} WAGES;

void sighandler(int i)
{
    printf("\n** Caught signal %d. Exiting...\n", i);
    exit(EXIT_FAILURE);
}

int readline(char* buffer)
{
    int count = 0;
    char ch;

    memset(buffer, 0x00, MAX_BUFFER_SIZE);
    ch = getchar();

    while ((ch != '\n') && (count < MAX_BUFFER_SIZE)) {
        buffer[count++] = ch;
        ch = getchar();
    }

    buffer[count] = 0x00;   /* null-terminate */
    return strlen(buffer);
}

int main(int argc, char* argv[])
{
  int hours=0, ot=0, maxemp=0, numemp=0;
  float premium=0, totalpay=0, maxpay=0;
  char buf[MAX_BUFFER_SIZE];

  WAGES emp[MAX_EMPLOYEES];

  signal(SIGINT,  sighandler);

  printf("\nEnter the overtime premium percentage: ");
  readline(buf);
  premium = MAX(atof(buf), 1);

  for (register int i=0; i < MAX_EMPLOYEES; ) {
    printf("\nEnter the hours worked by employee %d: ", i+1);
    readline(buf);

    hours = atoi(buf);
    ot    = MAX(0, (hours - STD_HOURS));
    hours = MIN(hours, STD_HOURS);

    printf("\nStandard hours: %d\n", hours);
    printf("Overtime hours: %d\n", ot);
    printf("\nIs this correct? (y/n): ");
    readline(buf);

    if (toupper(buf[0]) == 'Y')
        numemp++;
    else
        continue;

    emp[i].std   = (float)(hours * WAGE);
    emp[i].ot    = (float)((WAGE * premium) * ot);
    emp[i].total = (float)(emp[i].std + emp[i].ot);

    printf("\nWAGES:\n");
    printf("Standard:  %.2f\n", emp[i].std);
    printf("Overtime:  %.2f\n", emp[i].ot);
    printf("Total:     %.2f\n", emp[i].total);

    totalpay += emp[i].total;

    if (emp[i].total > maxpay) {
      maxpay = emp[i].total;
      maxemp = i+1;
    }

    printf("\nEnter wages for another employee? (y/n): ");
    readline(buf);

    if (toupper(buf[0]) == 'Y') {
      i++;
      continue;
    }
    break;
  }

  printf("\nTotal pay for %d employees: %.2f\n", numemp, totalpay);
  printf("The max earner was employee %d with %.2f\n", maxemp, maxpay);
  printf("\nWAGE LIST:\n");

  for (i=0; i < numemp; i++)
    printf("Employee %d: %.2f\n", i+1, emp[i].total);

  return EXIT_SUCCESS;
}

Last edited by WetWired; 2004-10-19 at 12:14 PM. Reason: Added [code] tag
Old
Profile PM WWW Search
deadlock75 is neither ape nor machine; has so far settled for the in-betweendeadlock75 is neither ape nor machine; has so far settled for the in-between
 
deadlock75
 



 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum 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
Forum Jump


All times are GMT -6. The time now is 10:33 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.