Thread: How can I do a gross payment program with overtime pay in C?

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    1

    Angry How can I do a gross payment program with overtime pay in C?

    The more I work on doing this problem the more lost i get.
    Im using simple arithmetic and am not sure if I need to use if else statements or while loops, or both. I also need to be able to separate the overtime hours for overtime pay and add them to the regular other 40 hrs. I have been at this problem for 2 weeks now and my brain is done. If anybody can give me a nudge in the right direction I would greatly appreciate it. thnx

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Can you show us your code so we can see what you've tried? Then we can show you how to fix it.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Just don't use floats for either value. Use integer cents for the money, and if there are partial hours, use integer minutes.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    Hi. I had to make a new profile. The other one was not letting me log in or change my pw. Anyway, this is what I have done so far
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    main(){
    	
    	double ovr = 4.0, grossOvrPay, regPay, hrs, rte = 8;
    	
    	printf ("How many hours did you work this week?\n");
    	scanf ("%lf", &hrs);
    
    
    	if (hrs <= 40)
    		{
    		printf("You have no overtime.\n");
    	}
    		
    	else
    		if (hrs > 40)
    			grossOvrPay = (hrs - 40) * rte + ovr + 320;// + $320 is total pay of 40hrs *8//
    	printf ("Your gross pay is: %lf\n", grossOvrPay);
    	
    
    
    	system("pause");
    
    
    }
    Im having trouble defining what the time and a half should be, the arithmetic gives me the wrong answer anything after 42hrs i believe. I feel that I am so close. But im out of ideas. any input you might have Ill greatly appreciate it

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    ovr has to get time and a half, I have tried .5 and 1.5 and now the 4 you see in this code i just sent. but nothing works after the 42 hrs. perhaps my arithmetic is wrong at the bottom? although i tired it with a calculator using the .5 and I get the right result. Maybe its the double messing with it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Monthly Payment Program Help
    By sharingan_gv in forum C Programming
    Replies: 7
    Last Post: 07-14-2011, 09:07 AM
  2. monthly payment from math to C++
    By summerwine in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2010, 05:31 PM
  3. program for finding gross salary
    By newbcore in forum C Programming
    Replies: 7
    Last Post: 12-05-2008, 06:23 PM
  4. Oh my lord...gross
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-24-2003, 10:57 PM
  5. Bet Payment: Kermi
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-20-2003, 08:00 PM