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

 
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
 



 
Reply
Posted 2004-10-19, 12:25 PM in reply to deadlock75's post "C programming Pay Rate"
Overtime hours or pay isn't right? Have you tried stepping through it in a debugger to check where the values deviate from your expectations?
Old
Profile PM WWW Search
WetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusion
 
 
WetWired
 



 
Reply
Posted 2004-10-19, 01:40 PM in reply to WetWired's post starting "Overtime hours or pay isn't right? ..."
WetWired said:
Overtime hours or pay isn't right? Have you tried stepping through it in a debugger to check where the values deviate from your expectations?
I don't know how to debug it through to find out why the overtime is a lot more than regular pay. Even if the overtime hour is 1 it will go more than the standard hour payment.
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
 



 
Reply
Posted 2004-10-19, 03:26 PM in reply to deadlock75's post starting "I don't know how to debug it through to..."
What toolset are you using?
Old
Profile PM WWW Search
WetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusion
 
 
WetWired
 



 
Reply
Posted 2004-10-19, 05:37 PM in reply to WetWired's post starting "What toolset are you using?"
i dunno what is a toolset
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
 



 
Reply
Posted 2004-10-19, 10:12 PM in reply to deadlock75's post starting "i dunno what is a toolset"
deadlock75 said:
i dunno what is a toolset
Okay, you're compiling your program somehow, how do you do that? What's the name of the program that you use to compile your program, and who makes it?
Old
Profile PM WWW Search
WetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusion
 
 
WetWired
 



 
Reply
Posted 2004-10-20, 04:13 PM in reply to WetWired's post starting "Okay, you're compiling your program..."
Turbo C++ thats the compiler that I am using
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
 



 
Reply
Posted 2004-10-20, 09:56 PM in reply to deadlock75's post starting "Turbo C++ thats the compiler that I am..."
deadlock75 said:
Turbo C++ thats the compiler that I am using
Okay, so you're using Borland Turbo C++. I've used the IDE before, but a long time ago. Off the top of my head, Ctrl-F9 runs, F7 steps into, and F8 steps over. Some modifier (shift?) with F4 runs the program to the point where the cursor is. IIRC, you can right click a line and choose to add a breakpoint. After compiling (F9 or Alt-F9), try just hitting F8 (otherwise, set a breakpoint on the first line of main, then hit Ctrl-F9). Hitting F8 repeatedly will show you the program flow. What you need to do is to set up watches for all the variables, then step through the code and watch the values of the variables, confirming that they have the values you expect at all times. I don't recall how to set up watches, but if you look through the menus once you've started debugging, it should be easy enough to figure out.
Old
Profile PM WWW Search
WetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusion
 
 
WetWired
 
 

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 02:54 PM.
'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 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.