//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();
}

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.

#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();
}

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();
}

Instead of putting the whole thing in main(), why not make one or two different functions for computing the total salary and gross salary.

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()

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

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();
}

Instead of putting the whole thing in main(), why not make one or two different functions for computing the total salary and gross salary.

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()

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

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();
}
This question has already been answered. Start a new discussion instead.