Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hello all I need to modify this program to use a sentinal loop so once the value

ID: 3552470 • Letter: H

Question

hello all I need to modify this program to use a sentinal loop so once the value of -99 is entered after getting the pay and hours the program should end. I cant get this to work. It works without the if statement but not with it.


#include <stdio.h>
#define SENTINAL -99
int
main (void)
{

    double     total_pay;        //company payroll
    int     count_emp;        //current employees
    int        number_emp;        //number of employees
    double     hours;            //hours worked
    double     rate;            //hourly rate
    double     pay;            // pay for period

    /* Get number of employeed. */
    printf ("Enter total number of employees> ");
    scanf("%d", &number_emp);
   
    /* Compute each employees pay and add it to the payroll*/
    total_pay = 0.0;
    count_emp = 0;
   
   
   
    while (count_emp < number_emp)
    {
        printf ("Hours> ");
        scanf ("%lf", &hours);
        printf ("rate> ");
        scanf ("%lf", &rate);
       
        if (hours != SENTINAL){
        pay = hours * rate;
        printf("Pay is $%6.2f ",pay);
        total_pay = total_pay + pay;
        count_emp = count_emp + 1;
        }
    }
   
    printf ("All employees processed ");
    printf ("Total payroll is $%8.2f ", total_pay);
   
return (0);   
}

Explanation / Answer

#include <stdio.h>

#define SENTINAL -99

int

main (void)

{


double total_pay; //company payroll

int count_emp; //current employees

int number_emp; //number of employees

double hours; //hours worked

double rate; //hourly rate

double pay; // pay for period


/* Get number of employeed. */

printf ("Enter total number of employees> ");

scanf("%d", &number_emp);

/* Compute each employees pay and add it to the payroll*/

total_pay = 0.0;

count_emp = 0;

do

{

printf ("Hours> ");

scanf ("%lf" ,&hours);

if(hours!= SENTINAL)

{

printf ("rate> ");

scanf ("%lf", &rate);

pay = hours * rate;

printf("Pay is $%6.2f ",pay);

total_pay = total_pay + pay;

count_emp = count_emp + 1;

break;

}

}while(number_emp < count_emp);

printf ("All employees processed ");

printf ("Total payroll is $%8.2f ", total_pay);

return (0);   

}