473,508 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating salary

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.

Apr 21 '07 #1
8 14752

"hmmtn" <hm*****@hotmail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
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

Apr 21 '07 #2
"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>
Apr 21 '07 #3
On Apr 21, 3:17 pm, "osmium" <r124c4u...@comcast.netwrote:
"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.

Apr 21 '07 #4
"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.
Apr 21 '07 #5
On Apr 21, 4:13 pm, "osmium" <r124c4u...@comcast.netwrote:
"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;
}
Apr 21 '07 #6
"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 );

Apr 21 '07 #7
On Apr 21, 4:46 pm, "osmium" <r124c4u...@comcast.netwrote:
"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.

Apr 21 '07 #8

A model home work question!

In article <11*********************@b75g2000hsg.googlegroups. com>, hmmtn
<hm*****@hotmail.comwrites
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 /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Apr 22 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5342
by: Eric Whittaker | last post by:
here's my dilemma, on the program below, i am trying to calculate overtime pay at time and a half, but instead of only counting the hours after 40, it counts all hrs at that rate, how can i avoid...
2
1945
by: Deano | last post by:
OK, I'm working on a solution to the following problem but there are other ways to skin a cat as they say... Here's the table (simplified); ID EmployeeName SalaryAcc 1 Brown ...
5
8852
by: Stu | last post by:
What are .NET programmers making now a days? No one has to answer or give their exact salary, but I think it might be useful for those of us who think they might be underpaid :) I know it varies a...
1
11494
by: sallyk57 | last post by:
Help with following Programs: Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will...
1
3871
by: punkybrewster | last post by:
Basically my task is to write a program that computes and displays the weekly salaries of a company's salespeople based upon information entered by the user and that also displays the total for the...
1
2380
by: hakunamatata5254 | last post by:
Hi all, In my project of multiple forms (main form, subform1, 2 , 3 etc) (Main form is Employees, Subforms are Attendance, salary details, payment) Now i want to calculate the payment based...
5
8554
by: james121285 | last post by:
This is to calculate an employees tax and pension. The salary is input from the keyboard. The NI contribution is calculated as 6% of the gross salary. The pension contribution is calculated as 2%...
4
7497
by: sonia.sardana | last post by:
I know how how to retrive the largest & second largest salary. tell me how to retrive the 3,4,5,...............Largest salary. Create table empl(empid int, empname varchar,salary int) insert...
1
10216
by: ygsunilkumar | last post by:
select distinct (a.salary) from employees a where &N = (select count (distinct(b.salary)) from employees b where a.salary <= b.salary); Pls any one explain how the query works, logic behind it.
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.