Calculating salary

H

hmmtn

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.
 
M

Malcolm McLean

hmmtn said:
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);
 
O

osmium

hmmtn said:
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>
 
H

hmmtn

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.
 
O

osmium

hmmtn said:
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.
 
H

hmmtn

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;
}
 
O

osmium

hmmtn said:
#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 );
 
H

hmmtn

<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.
 
C

Chris Hills

A model home work question!

hmmtn said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top