| | |
Salary problem...(Beginner)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 32
Reputation:
Solved Threads: 0
//Make an interactive program that will ask for
hourly rate of the employee and the number of
hours worked in a day. As DOLE mandates, more
than 8 hours of work a day is considered OT
(overtime) so the wage will be 1.5 * hourly
rate after the 8 hours of work.using loops,
compute the weekly wage.Given 6 days of work
in a week.Output the gross salary and net
salary( gross salary less 12%.)//
I dont know how work with the overtime...
here's my code..
hourly rate of the employee and the number of
hours worked in a day. As DOLE mandates, more
than 8 hours of work a day is considered OT
(overtime) so the wage will be 1.5 * hourly
rate after the 8 hours of work.using loops,
compute the weekly wage.Given 6 days of work
in a week.Output the gross salary and net
salary( gross salary less 12%.)//
I dont know how work with the overtime...
here's my code..
#include <stdio.h>
int main()
{
int day,hRate,wHours,;
int total = 0;
int i = 1;
float cTax,gross,salary,nSalary,aTotal;
float tax = .12;
printf("Enter Hourly Rate: ");
scanf("%d",&hRate);
printf("Enter number of days you've worked: ");
scanf("%d",&day);
if (i <= day)
{
while (i <= day)
{
printf("\nEnter number of hours you worked in Day %d: ",i);
scanf("%d",&wHours);
salary=wHours*hRate;
printf("\nYour salary for day %d is %.2f \n",i,salary);
i=i+1;
total=total+salary;
}
}
else
if ( wHours > 8)
{
while (i <= day)
{
printf("\nEnter number of hours you worked in Day %d: ",i);
scanf("%d",&wHours);
salary=wHours*(hRate*1.5);
printf("\nYour salary for day %d is %.2f \n",i,salary);
i=i+1;
total=total+salary;
}
}
aTotal = total;
printf("\nYour weekly gross salary is %.2f", aTotal);
cTax =tax*total;
printf("\n\n the tax is %.2f",cTax );
gross=aTotal-cTax;
printf("\n\n weekly net salary is %.2f", gross);
getchar();
getchar();
}•
•
Join Date: Oct 2008
Posts: 103
Reputation:
Solved Threads: 14
You need to follow your code--execute your code on paper. Follow line by line and write down on paper what the values are for the variables. For example: if (i <= day). You set i=1. So unless the user enters a value for day of "0" this will always get executed. If a someone worked "0" days, then there is no reason to run this program. No work = no pay.
I didn't look through/correct all of your code, but I've modified your code a bit to help you along.
I didn't look through/correct all of your code, but I've modified your code a bit to help you along.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int day; int i = 1; //wHours should be float because people work partial hours sometimes float wHours; //hRate should be float because people aren't paid only in whole dollar amounts float hRate; float total = 0.0; float cTax,gross,salary,nSalary,aTotal; float tax = .12; printf("Enter Hourly Rate: "); scanf("%f",&hRate); printf("Enter number of days you've worked: "); scanf("%d",&day); while (i <= day) { printf("\nEnter number of hours you worked in Day %d: ",i); scanf("%f",&wHours); if (wHours > 8.0) { //what do you want to do if wHours > 8 ??? } else { salary=wHours*hRate; } printf("\nYour salary for day %d is %.2f \n",i,salary); i=i+1; total=total+salary; } aTotal = total; printf("\nYour weekly gross salary is %.2f", aTotal); cTax =tax*total; printf("\n\n the tax is %.2f",cTax ); gross=aTotal-cTax; printf("\n\n weekly net salary is %.2f", gross); getchar(); getchar(); }
Last edited by cgeier; Jul 29th, 2009 at 12:27 pm.
•
•
Join Date: Oct 2008
Posts: 44
Reputation:
Solved Threads: 11
•
•
•
•
I dont know how work with the overtime...
here's my code..
c Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int day,hRate,wHours,; int total = 0; int i = 1; float cTax,gross,salary,nSalary,aTotal; float tax = .12; printf("Enter Hourly Rate: "); scanf("%d",&hRate); printf("Enter number of days you've worked: "); scanf("%d",&day); if (i <= day) { while (i <= day) { printf("\nEnter number of hours you worked in Day %d: ",i); scanf("%d",&wHours); salary=wHours*hRate; printf("\nYour salary for day %d is %.2f \n",i,salary); i=i+1; total=total+salary; } } else if ( wHours > 8) { while (i <= day) { printf("\nEnter number of hours you worked in Day %d: ",i); scanf("%d",&wHours); salary=wHours*(hRate*1.5); printf("\nYour salary for day %d is %.2f \n",i,salary); i=i+1; total=total+salary; } } aTotal = total; printf("\nYour weekly gross salary is %.2f", aTotal); cTax =tax*total; printf("\n\n the tax is %.2f",cTax ); gross=aTotal-cTax; printf("\n\n weekly net salary is %.2f", gross); getchar(); getchar(); }
c Syntax (Toggle Plain Text)
const int OVERTIME_MULTIPLE = 1.5; const int HOURS_PER_DAY = 8; int salaryPerDay(int numberOfHours, int rate) { if (numberOfHours <= HOURS_PER_DAY) return(numberOfHours * rate) ; return ( (numberOfHours - HOURS_PER_DAY) * OVERTIME_MULTIPLE * rate + (HOURS_PER_DAY * rate) ); }
Now in main()
c Syntax (Toggle Plain Text)
const int DAYS_IN_A_WEEK = 6; int weekNumber = 1; int weekSalary = 0; while (i <= day) { printf("\nEnter number of hours you worked in Day %d: ",i); scanf("%d",&wHours); /*Assuming the data entered is "what you expect"*/ salary=salaryPerDay(wHours,hRate); /*Whether or not ,the person overworked, the function will take care*/ weekSalary += salary; printf("\nYour salary for day %d is %.2f \n",i,salary); i++; /*compute the weekly wage*/ if (i % DAYS_IN_A_WEEK == 0) { printf ("Salary for #%d is %d", weekNumber, weekSalary); weekSalary = 0; /*A new week begins*/ weekNumber++; /*Next week*/ } total=total+salary; }
Last edited by zalezog; Jul 29th, 2009 at 12:34 pm.
•
•
Join Date: Jun 2009
Posts: 32
Reputation:
Solved Threads: 0
Thanks for the idea guys i already solved it...
if you worked OT...The rate shud be (hRate*1.5)...Only the hours that you've OT will be multiplied the hRate by 1.5...Not the whole wHours...
So here's the final code...
if you worked OT...The rate shud be (hRate*1.5)...Only the hours that you've OT will be multiplied the hRate by 1.5...Not the whole wHours...
So here's the final code...
#include <stdio.h>
int main()
{
int day,hRate,wHours,;
int total = 0;
int i = 1;
float cTax,gross,salary,nSalary,aTotal,OT;
float tax = .12;
printf("Enter Hourly Rate: ");
scanf("%d",&hRate);
printf("Enter number of days you've worked: ");
scanf("%d",&day);
if (i <= day)
{
while (i <= day)
{
printf("\nEnter number of hours you worked in Day %d: ",i);
scanf("%d",&wHours);
if ( wHours > 8)
{
OT=((wHours-8)*(hRate*1.5))+wHours*hRate;
printf("\nYour salary for day %d is %.2f \n",i,OT);
}
else
{
salary=wHours*(hRate);
printf("\nYour salary for day %d is %.2f \n",i,salary);
}
total=total+salary;
i++;
}
}
aTotal = total;
printf("\nYour weekly gross salary is %.2f", aTotal);
cTax =tax*total;
printf("\n\n the tax is %.2f",cTax );
gross=aTotal-cTax;
printf("\n\n weekly net salary is %.2f", gross);
getchar();
getchar();
}•
•
Join Date: Jun 2009
Posts: 32
Reputation:
Solved Threads: 0
•
•
•
•
Instead of putting the whole thing in main(), why not make one or two different functions for computing the total salary and gross salary.
c Syntax (Toggle Plain Text)
const int OVERTIME_MULTIPLE = 1.5; const int HOURS_PER_DAY = 8; int salaryPerDay(int numberOfHours, int rate) { if (numberOfHours <= HOURS_PER_DAY) return(numberOfHours * rate) ; return ( (numberOfHours - HOURS_PER_DAY) * OVERTIME_MULTIPLE * rate + (HOURS_PER_DAY * rate) ); }
Now in main()
c Syntax (Toggle Plain Text)
const int DAYS_IN_A_WEEK = 6; int weekNumber = 1; int weekSalary = 0; while (i <= day) { printf("\nEnter number of hours you worked in Day %d: ",i); scanf("%d",&wHours); /*Assuming the data entered is "what you expect"*/ salary=salaryPerDay(wHours,hRate); /*Whether or not ,the person overworked, the function will take care*/ weekSalary += salary; printf("\nYour salary for day %d is %.2f \n",i,salary); i++; /*compute the weekly wage*/ if (i % DAYS_IN_A_WEEK == 0) { printf ("Salary for #%d is %d", weekNumber, weekSalary); weekSalary = 0; /*A new week begins*/ weekNumber++; /*Next week*/ } total=total+salary; }
Can you explain me what is this
weekSalary += salary; I don't know what is that... Last edited by DoEds; Aug 5th, 2009 at 2:14 am. Reason: Mark as Solved.
•
•
Join Date: Jun 2009
Posts: 32
Reputation:
Solved Threads: 0
Aw...Sorry...
Here's the final code...
Here's the final code...
#include <stdio.h>
int main()
{
int day,hRate,wHours,;
int total = 0;
int i = 1;
float cTax,gross,salary,nSalary,aTotal;
float tax = .12;
printf("Enter Hourly Rate: ");
scanf("%d",&hRate);
printf("Enter number of days you've worked: ");
scanf("%d",&day);
if (i <= day)
{
while (i <= day)
{
printf("\nEnter number of hours you worked in Day %d: ",i);
scanf("%d",&wHours);
if ( wHours > 8 )
{
salary=((wHours - 8)*(hRate*1.5))+(8*hRate);
printf("\nYour salary for day %d is %.2f \n",i,salary);
}
else
{
salary=wHours*(hRate);
printf("\nYour salary for day %d is %.2f \n",i,salary);
}
total=total+salary;
i++;
}
aTotal = total;
printf("\nYour weekly gross salary is %.2f", aTotal);
cTax =tax*total;
printf("\n\n the tax is %.2f",cTax );
gross=aTotal-cTax;
printf("\n\n weekly net salary is %.2f", gross);
}
getchar();
getchar();
}![]() |
Similar Threads
- If and while statement problem (Beginner) (C)
- perl loop problem (from a beginner) (Perl)
- Body Text lost when sending hotmail (Web Browsers)
- Can any one help me with java application (Java)
- Some Help with a simple C++ class. (C++)
- declaration syntax error? (C++)
- 10, 20, 0 (C)
Other Threads in the C Forum
- Previous Thread: Pointers and Sorting Array by Even and Odd numbers
- Next Thread: Pointer Issues in C
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char character convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush fgets file floatingpointvalidation fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest intmain() kilometer license linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings structures suggestions test testautomation unix urboc user voidmain() win32api windows.h





