Salary problem...(Beginner)

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2009
Posts: 32
Reputation: DoEds is an unknown quantity at this point 
Solved Threads: 0
DoEds DoEds is online now Online
Light Poster

Salary problem...(Beginner)

 
0
  #1
Jul 29th, 2009
//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..
#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();
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 103
Reputation: cgeier is an unknown quantity at this point 
Solved Threads: 14
cgeier cgeier is offline Offline
Junior Poster

Re: Salary problem...(Beginner)

 
0
  #2
Jul 29th, 2009
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.

  1.  
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6. int day;
  7. int i = 1;
  8. //wHours should be float because people work partial hours sometimes
  9. float wHours;
  10. //hRate should be float because people aren't paid only in whole dollar amounts
  11. float hRate;
  12. float total = 0.0;
  13. float cTax,gross,salary,nSalary,aTotal;
  14. float tax = .12;
  15.  
  16. printf("Enter Hourly Rate: ");
  17. scanf("%f",&hRate);
  18. printf("Enter number of days you've worked: ");
  19. scanf("%d",&day);
  20.  
  21.  
  22. while (i <= day)
  23. {
  24. printf("\nEnter number of hours you worked in Day %d: ",i);
  25. scanf("%f",&wHours);
  26.  
  27. if (wHours > 8.0)
  28. {
  29. //what do you want to do if wHours > 8 ???
  30.  
  31. }
  32. else
  33. {
  34. salary=wHours*hRate;
  35. }
  36.  
  37. printf("\nYour salary for day %d is %.2f \n",i,salary);
  38. i=i+1;
  39. total=total+salary;
  40.  
  41. }
  42.  
  43.  
  44. aTotal = total;
  45. printf("\nYour weekly gross salary is %.2f", aTotal);
  46. cTax =tax*total;
  47. printf("\n\n the tax is %.2f",cTax );
  48. gross=aTotal-cTax;
  49. printf("\n\n weekly net salary is %.2f", gross);
  50.  
  51.  
  52. getchar();
  53. getchar();
  54. }
Last edited by cgeier; Jul 29th, 2009 at 12:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 44
Reputation: zalezog is an unknown quantity at this point 
Solved Threads: 11
zalezog zalezog is offline Offline
Light Poster

Re: Salary problem...(Beginner)

 
0
  #3
Jul 29th, 2009
I dont know how work with the overtime...

here's my code..
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int day,hRate,wHours,;
  6. int total = 0;
  7. int i = 1;
  8. float cTax,gross,salary,nSalary,aTotal;
  9. float tax = .12;
  10.  
  11. printf("Enter Hourly Rate: ");
  12. scanf("%d",&hRate);
  13. printf("Enter number of days you've worked: ");
  14. scanf("%d",&day);
  15.  
  16. if (i <= day)
  17. {
  18. while (i <= day)
  19. {
  20. printf("\nEnter number of hours you worked in Day %d: ",i);
  21. scanf("%d",&wHours);
  22.  
  23. salary=wHours*hRate;
  24. printf("\nYour salary for day %d is %.2f \n",i,salary);
  25. i=i+1;
  26. total=total+salary;
  27.  
  28. }
  29. }
  30. else
  31. if ( wHours > 8)
  32. {
  33. while (i <= day)
  34. {
  35. printf("\nEnter number of hours you worked in Day %d: ",i);
  36. scanf("%d",&wHours);
  37. salary=wHours*(hRate*1.5);
  38. printf("\nYour salary for day %d is %.2f \n",i,salary);
  39. i=i+1;
  40. total=total+salary;
  41. }
  42. }
  43. aTotal = total;
  44. printf("\nYour weekly gross salary is %.2f", aTotal);
  45. cTax =tax*total;
  46. printf("\n\n the tax is %.2f",cTax );
  47. gross=aTotal-cTax;
  48. printf("\n\n weekly net salary is %.2f", gross);
  49.  
  50.  
  51. getchar();
  52. getchar();
  53. }
Instead of putting the whole thing in main(), why not make one or two different functions for computing the total salary and gross salary.
  1. const int OVERTIME_MULTIPLE = 1.5;
  2. const int HOURS_PER_DAY = 8;
  3.  
  4. int salaryPerDay(int numberOfHours, int rate) {
  5. if (numberOfHours <= HOURS_PER_DAY)
  6. return(numberOfHours * rate) ;
  7.  
  8. return ( (numberOfHours - HOURS_PER_DAY) *
  9. OVERTIME_MULTIPLE * rate +
  10. (HOURS_PER_DAY * rate) );
  11.  
  12. }

Now in main()
  1.  
  2. const int DAYS_IN_A_WEEK = 6;
  3. int weekNumber = 1;
  4. int weekSalary = 0;
  5. while (i <= day)
  6. {
  7. printf("\nEnter number of hours you worked in Day %d: ",i);
  8. scanf("%d",&wHours);
  9. /*Assuming the data entered is "what you expect"*/
  10. salary=salaryPerDay(wHours,hRate);
  11. /*Whether or not ,the person overworked,
  12.   the function will take care*/
  13. weekSalary += salary;
  14. printf("\nYour salary for day %d is %.2f \n",i,salary);
  15. i++;
  16. /*compute the weekly wage*/
  17. if (i % DAYS_IN_A_WEEK == 0) {
  18. printf ("Salary for #%d is %d",
  19. weekNumber, weekSalary);
  20. weekSalary = 0; /*A new week begins*/
  21. weekNumber++; /*Next week*/
  22. }
  23. total=total+salary;
  24.  
  25. }
Last edited by zalezog; Jul 29th, 2009 at 12:34 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 32
Reputation: DoEds is an unknown quantity at this point 
Solved Threads: 0
DoEds DoEds is online now Online
Light Poster

Re: Salary problem...(Beginner)

 
0
  #4
Aug 5th, 2009
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...
#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();
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 32
Reputation: DoEds is an unknown quantity at this point 
Solved Threads: 0
DoEds DoEds is online now Online
Light Poster

Re: Salary problem...(Beginner)

 
0
  #5
Aug 5th, 2009
Originally Posted by zalezog View Post
Instead of putting the whole thing in main(), why not make one or two different functions for computing the total salary and gross salary.
  1. const int OVERTIME_MULTIPLE = 1.5;
  2. const int HOURS_PER_DAY = 8;
  3.  
  4. int salaryPerDay(int numberOfHours, int rate) {
  5. if (numberOfHours <= HOURS_PER_DAY)
  6. return(numberOfHours * rate) ;
  7.  
  8. return ( (numberOfHours - HOURS_PER_DAY) *
  9. OVERTIME_MULTIPLE * rate +
  10. (HOURS_PER_DAY * rate) );
  11.  
  12. }

Now in main()
  1.  
  2. const int DAYS_IN_A_WEEK = 6;
  3. int weekNumber = 1;
  4. int weekSalary = 0;
  5. while (i <= day)
  6. {
  7. printf("\nEnter number of hours you worked in Day %d: ",i);
  8. scanf("%d",&wHours);
  9. /*Assuming the data entered is "what you expect"*/
  10. salary=salaryPerDay(wHours,hRate);
  11. /*Whether or not ,the person overworked,
  12.   the function will take care*/
  13. weekSalary += salary;
  14. printf("\nYour salary for day %d is %.2f \n",i,salary);
  15. i++;
  16. /*compute the weekly wage*/
  17. if (i % DAYS_IN_A_WEEK == 0) {
  18. printf ("Salary for #%d is %d",
  19. weekNumber, weekSalary);
  20. weekSalary = 0; /*A new week begins*/
  21. weekNumber++; /*Next week*/
  22. }
  23. total=total+salary;
  24.  
  25. }
Can you show me the whole code? I really don't know how to use 2 functions.


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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 32
Reputation: DoEds is an unknown quantity at this point 
Solved Threads: 0
DoEds DoEds is online now Online
Light Poster

Re: Salary problem...(Beginner)

 
0
  #6
Aug 5th, 2009
Aw...Sorry...

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();
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC