Calculating salary

Discussion in 'C Programming' started by hmmtn, Apr 21, 2007.

  1. hmmtn

    hmmtn Guest

    I would appreciate any help on this one. Assignment is as
    follows: Develop a program that will determine the gross pay for each
    of several employees. The company pays "straight time" for the first
    40 hours worked by each employee and pays "time-and-a-half" for all
    hours worked in excess of 40 hours. You are given a list of the
    employees of the company, the number of hours each employee worked
    last week and the hourly rate of each employee. your program should
    input this information for each employee, and should determine and
    display the employee's gross pay.

    So far I have:

    #include <stdio.h>

    int main()
    {
    int hours;
    int rate;
    int salary;

    int counter = 0;

    printf( "Enter # of hours worked (-1 to end): " );
    scanf( "%d", &hours );

    printf( "Enter hourly rate of the worker ($00.00): " );
    scanf( "%d", &rate );

    while( hours != -1 )
    counter++;
    {
    if( hours <= 40 )
    {
    salary = rate * hours;
    }
    else
    {
    salary = 40 * rate + (hours - 40) * (rate * 1.5);
    }

    printf( "Salary is %d\n", salary );

    }
    return 0;
    }

    I can't get it to show salary, or begin another loop right now.
    Thanks in advance for any help.
    hmmtn, Apr 21, 2007
    #1
    1. Advertising

  2. "hmmtn" <> wrote in message
    news:...
    > I would appreciate any help on this one. Assignment is as
    > follows: Develop a program that will determine the gross pay for each
    > of several employees. The company pays "straight time" for the first
    > 40 hours worked by each employee and pays "time-and-a-half" for all
    > hours worked in excess of 40 hours. You are given a list of the
    > employees of the company, the number of hours each employee worked
    > last week and the hourly rate of each employee. your program should
    > input this information for each employee, and should determine and
    > display the employee's gross pay.
    >
    > So far I have:
    >
    > #include <stdio.h>
    >
    > int main()
    > {
    > int hours;
    > int rate;
    > int salary;
    >
    > int counter = 0;
    >
    > printf( "Enter # of hours worked (-1 to end): " );
    > scanf( "%d", &hours );
    >
    > printf( "Enter hourly rate of the worker ($00.00): " );
    > scanf( "%d", &rate );
    >
    > while( hours != -1 )
    > counter++;
    > {
    > if( hours <= 40 )
    > {
    > salary = rate * hours;
    > }
    > else
    > {
    > salary = 40 * rate + (hours - 40) * (rate * 1.5);
    > }
    >
    > printf( "Salary is %d\n", salary );
    >
    > }
    > return 0;
    > }
    >
    > I can't get it to show salary, or begin another loop right now.
    > Thanks in advance for any help.
    >

    You need to put the input in the main loop

    do
    {
    printf( "Enter # of hours worked (-1 to end): " );
    scanf( "%d", &hours );

    /* all your stuff here */

    } while(hours != -1);
    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Apr 21, 2007
    #2
    1. Advertising

  3. hmmtn

    osmium Guest

    "hmmtn" wrote:

    > I would appreciate any help on this one. Assignment is as
    > follows: Develop a program that will determine the gross pay for each
    > of several employees. The company pays "straight time" for the first
    > 40 hours worked by each employee and pays "time-and-a-half" for all
    > hours worked in excess of 40 hours. You are given a list of the
    > employees of the company, the number of hours each employee worked
    > last week and the hourly rate of each employee. your program should
    > input this information for each employee, and should determine and
    > display the employee's gross pay.
    >
    > So far I have:
    >
    > #include <stdio.h>
    >
    > int main()
    > {
    > int hours;
    > int rate;
    > int salary;
    >
    > int counter = 0;
    >
    > printf( "Enter # of hours worked (-1 to end): " );
    > scanf( "%d", &hours );
    >
    > printf( "Enter hourly rate of the worker ($00.00): " );


    Someone else has already pointed out your major problem. But that example
    is a problem waiting to happen. It encourages people to put in decimal
    numbers, but the program is designed to handle integers. I suggest changing
    hours, rate and salary to type double. Changing the declaration also require
    that you change to code for input/output, of course. Use a "fuzzy" test for
    40 hours, because a double is only a (very good) approximation to an
    integer.

    <snip>
    osmium, Apr 21, 2007
    #3
  4. hmmtn

    hmmtn Guest

    On Apr 21, 3:17 pm, "osmium" <> wrote:
    > "hmmtn" wrote:
    > > I would appreciate any help on this one. Assignment is as
    > > follows: Develop a program that will determine the gross pay for each
    > > of several employees. The company pays "straight time" for the first
    > > 40 hours worked by each employee and pays "time-and-a-half" for all
    > > hours worked in excess of 40 hours. You are given a list of the
    > > employees of the company, the number of hours each employee worked
    > > last week and the hourly rate of each employee. your program should
    > > input this information for each employee, and should determine and
    > > display the employee's gross pay.

    >
    > > So far I have:

    >
    > > #include <stdio.h>

    >
    > > int main()
    > > {
    > > int hours;
    > > int rate;
    > > int salary;

    >
    > > int counter = 0;

    >
    > > printf( "Enter # of hours worked (-1 to end): " );
    > > scanf( "%d", &hours );

    >
    > > printf( "Enter hourly rate of the worker ($00.00): " );

    >
    > Someone else has already pointed out your major problem. But that example
    > is a problem waiting to happen. It encourages people to put in decimal
    > numbers, but the program is designed to handle integers. I suggest changing
    > hours, rate and salary to type double. Changing the declaration also require
    > that you change to code for input/output, of course. Use a "fuzzy" test for
    > 40 hours, because a double is only a (very good) approximation to an
    > integer.
    >
    > <snip>


    Thanks for the help guys. So far, everything is working except for
    looping the inputs. It's supposed to look like:

    Enter # of hours worked (-1 to end): 39
    Enter hourly rate of the worker ($00.00): 10.00
    Salary is $390.00

    Enter # of hours worked (-1 to end): 40
    Enter hourly rate of the worker ($00.00): 10.00
    Salary is $400.00

    Enter # of hours worked (-1 to end): 41
    Enter hourly rate of the worker ($00.00): 10.00
    Salary is $415.00

    Enter # of hours worked (-1 to end): -1

    I can't figure out how to continue entering hours and rates until you
    input -1 for hours.
    hmmtn, Apr 21, 2007
    #4
  5. hmmtn

    osmium Guest

    "hmmtn" wrote:

    > I can't figure out how to continue entering hours and rates until you
    > input -1 for hours.


    Post the code you wrote containing at least one while statement, as proposed
    by Malcolm.
    osmium, Apr 21, 2007
    #5
  6. hmmtn

    hmmtn Guest

    On Apr 21, 4:13 pm, "osmium" <> wrote:
    > "hmmtn" wrote:
    > > I can't figure out how to continue entering hours and rates until you
    > > input -1 for hours.

    >
    > Post the code you wrote containing at least one while statement, as proposed
    > by Malcolm.


    #include <stdio.h>

    int main()
    {
    int hours;
    int rate;
    int salary;

    int counter = 0;

    printf( "Enter # of hours worked (-1 to end): " );
    scanf( "%d", &hours );

    printf( "Enter hourly rate of the worker ($00.00): " );
    scanf( "%d", &rate );

    {
    if( hours <= 40 )
    {
    salary = rate * hours;
    printf( "Salary is $%d\n", salary );
    }
    else
    {
    salary = 40 * rate + (hours - 40) * (rate * 1.5);
    printf( "Salary is $%d\n", salary );
    }
    }

    while( hours != -1 );
    counter++;

    return 0;
    }
    hmmtn, Apr 21, 2007
    #6
  7. hmmtn

    osmium Guest

    "hmmtn" wrote:

    > #include <stdio.h>
    >
    > int main()
    > {
    > int hours;
    > int rate;
    > int salary;
    >
    > int counter = 0;

    <snip>

    Here is the innards of your program. I cut and pasted into my environment
    for testing and I did a very rough indent to get a some idea of what was
    supposed to happen. There are three or so changes, I'll let you find them.

    int hours;
    int rate;
    double salary;

    int counter = 0;

    do
    {
    printf( "Enter # of hours worked (-1 to end): " );
    scanf( "%d", &hours );

    printf( "Enter hourly rate of the worker ($00.00): " );
    scanf( "%d", &rate );


    if( hours <= 40 )
    {
    salary = rate * hours;
    printf( "Salary is $%f\n", salary );
    }
    else
    {
    salary = 40 * rate + (hours - 40) * (rate * 1.5);
    printf( "Salary is $%f\n", salary );
    }

    counter++;
    }while( hours != -1 );
    osmium, Apr 21, 2007
    #7
  8. hmmtn

    hmmtn Guest

    On Apr 21, 4:46 pm, "osmium" <> wrote:
    > "hmmtn" wrote:
    > > #include <stdio.h>

    >
    > > int main()
    > > {
    > > int hours;
    > > int rate;
    > > int salary;

    >
    > > int counter = 0;

    >
    > <snip>
    >
    > Here is the innards of your program. I cut and pasted into my environment
    > for testing and I did a very rough indent to get a some idea of what was
    > supposed to happen. There are three or so changes, I'll let you find them.
    >
    > int hours;
    > int rate;
    > double salary;
    >
    > int counter = 0;
    >
    > do
    > {
    > printf( "Enter # of hours worked (-1 to end): " );
    > scanf( "%d", &hours );
    >
    > printf( "Enter hourly rate of the worker ($00.00): " );
    > scanf( "%d", &rate );
    >
    > if( hours <= 40 )
    > {
    > salary = rate * hours;
    > printf( "Salary is $%f\n", salary );
    > }
    > else
    > {
    > salary = 40 * rate + (hours - 40) * (rate * 1.5);
    > printf( "Salary is $%f\n", salary );
    > }
    >
    > counter++;
    > }while( hours != -1 );


    Alright, finally got it working. Thank you very much for all the help
    guys.
    hmmtn, Apr 21, 2007
    #8
  9. hmmtn

    Chris Hills Guest

    A model home work question!

    In article <>, hmmtn
    <> writes
    > I would appreciate any help on this one. Assignment is as
    >follows:


    Honesty always pays when seeking help for homework. Let that be a lesson
    to the rest of you! Otherwise you will get flamed or answers your
    lecturer will KNOW you neither did nor understand.


    > So far I have:
    >
    >#include <stdio.h>
    >
    >int main()
    >{
    > int hours;


    Include the code to show you have done some work yourself. People WILL
    help if you have had a go at it yourself.

    > I can't get it to show salary, or begin another loop right now.


    Try and be specific about the problem... "it don't work" is no good to
    anyone.

    >Thanks in advance for any help.


    Be polite and use proper grammar punctuation as best you can. WKS or
    TXT speak pisses people right off.

    By following these simple rules as the OP did will get you results quite
    quickly.

    Now.......

    No cn sum 1 snd me cod for complete salary database & payroll to my
    email as I am late with urgent project.... :)

    PS cct 4 mater transporter would be good too.



    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    Chris Hills, Apr 22, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The job lady
    Replies:
    0
    Views:
    541
    The job lady
    Jan 13, 2006
  2. Simon Harris

    Salary Expectations (UK)

    Simon Harris, Oct 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,620
    Mark Rae
    Oct 16, 2004
  3. Lucas Tam
    Replies:
    5
    Views:
    9,532
    Karl Seguin
    May 13, 2005
  4. Balu
    Replies:
    1
    Views:
    345
    Juan T. Llibre
    Feb 24, 2006
  5. Balu
    Replies:
    1
    Views:
    339
    darrel
    Feb 25, 2006
Loading...

Share This Page