Connecting Tech Pros Worldwide Forums | Help | Site Map

Calculating salary

hmmtn
Guest
 
Posts: n/a
#1: Apr 21 '07
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.


Malcolm McLean
Guest
 
Posts: n/a
#2: Apr 21 '07

re: Calculating salary



"hmmtn" <hmmtn81@hotmail.comwrote in message
news:1177184815.787212.53350@b75g2000hsg.googlegro ups.com...
Quote:
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



osmium
Guest
 
Posts: n/a
#3: Apr 21 '07

re: Calculating salary


"hmmtn" wrote:
Quote:
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>


hmmtn
Guest
 
Posts: n/a
#4: Apr 21 '07

re: Calculating salary


On Apr 21, 3:17 pm, "osmium" <r124c4u...@comcast.netwrote:
Quote:
"hmmtn" wrote:
Quote:
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.
>
Quote:
So far I have:
>
Quote:
#include <stdio.h>
>
Quote:
int main()
{
int hours;
int rate;
int salary;
>
Quote:
int counter = 0;
>
Quote:
printf( "Enter # of hours worked (-1 to end): " );
scanf( "%d", &hours );
>
Quote:
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.

osmium
Guest
 
Posts: n/a
#5: Apr 21 '07

re: Calculating salary


"hmmtn" wrote:
Quote:
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.


hmmtn
Guest
 
Posts: n/a
#6: Apr 21 '07

re: Calculating salary


On Apr 21, 4:13 pm, "osmium" <r124c4u...@comcast.netwrote:
Quote:
"hmmtn" wrote:
Quote:
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;
}


osmium
Guest
 
Posts: n/a
#7: Apr 21 '07

re: Calculating salary


"hmmtn" wrote:
Quote:
#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 );



hmmtn
Guest
 
Posts: n/a
#8: Apr 21 '07

re: Calculating salary


On Apr 21, 4:46 pm, "osmium" <r124c4u...@comcast.netwrote:
Quote:
"hmmtn" wrote:
Quote:
#include <stdio.h>
>
Quote:
int main()
{
int hours;
int rate;
int salary;
>
Quote:
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.

Chris Hills
Guest
 
Posts: n/a
#9: Apr 22 '07

re: Calculating salary



A model home work question!

In article <1177184815.787212.53350@b75g2000hsg.googlegroups. com>, hmmtn
<hmmtn81@hotmail.comwrites
Quote:
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.

Quote:
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.
Quote:
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.
Quote:
>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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



Closed Thread