Thread: Help With HW

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    Help With HW

    Okay so by now i have a whole bunch of scanf, and printf on my code but i want other people help, like how would you do it, and i forget what function i use if the number cant be a whole number here is the assignment.Am I on the right path or is there an easier way to approach this. My code is the bottom.

    Write a program that reads in the name, hourly rate and number of hours worked for 5 people. Print the name of each person, the number of hours worked, their weekly pay based on the number of hours they worked and how much they owe in taxes. Assume that taxes take 20% of the paycheck. Don’t forget to take the taxes out of the pay check. If they work more than 40 hours they get overtime. The hourly rate is then 1.5 times normal for all hours past 40.

    Example (Sample input & output for one person)
    Enter name: Glenn
    Enter hourly rate: 4.00
    Enter hours worked: 75

    Pay to: Glenn
    Hourly rate: 4.00
    Hours worked: 75.0
    Amount paid: $370.00
    Taxes paid: $74.00

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main (void)
    {
    int num1;
    int num2;
    int sum;
    printf("Glenn\n");
    printf("Enter Hourly Rate\n");
    scanf("%d", &num1);
    printf("Enter Hours Worked\n");
    scanf("%d", &num2);
    sum = num1 * num2;
    printf(" The Total Is %d", sum);
    getch();
    }
    Last edited by Salem; 05-28-2010 at 10:11 AM. Reason: Use [code][/code] tags for code! - see the intro threads

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    If you have covered them, this is probably best done with structures(Cprogramming.com Tutorial: Structures) and Loops(Cprogramming.com Tutorial: Loops). If not then this is could be quite a painful experience.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Start by giving your variables meaningful names, like hourlyRate and hoursWorked.

    Then things like
    if ( hoursWorked > 40 )

    is likely to make a lot more sense than
    if ( num2 > 40 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 12-05-2008, 12:47 PM
  2. ioctl request to get the HW address
    By threahdead in forum Linux Programming
    Replies: 7
    Last Post: 01-03-2008, 01:34 AM
  3. Help with HW
    By DontBugMe in forum C++ Programming
    Replies: 7
    Last Post: 04-11-2006, 10:45 AM
  4. HW help
    By ccwash in forum C++ Programming
    Replies: 4
    Last Post: 10-20-2005, 06:55 PM
  5. Hw
    By SAMSAM in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-23-2003, 06:17 AM