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

I\'m trying to make a simple program using C in Visual Studio to calculate gross

ID: 3538444 • Letter: I

Question

I'm trying to make a simple program using C in Visual Studio to calculate gross pay, with the conditions that I need to read the hourly rate, and the amount of hours worked by the employee, then display the hours, hourly rate, and gross pay of the employee. If the hours worked exceed 40 compute the overtime will be paid 1.5 *hourly rate. This is what I've got so far, but I don't seem to be doing it right...

#include <stdio.h>
#include <stdlib.h>

main()
{
    double payrate, hoursWorked, grossPayrate;
   

    system("pause")

    printf("Enter your payrate: ");
    scanf("%lf", &payrate);
    printf("Your payrate per hour is %.2lf ", payrate);

    printf("Enter how many hours you've worked: ");
    scanf("%lf", &hoursWorked);
    printf("You've worked %.2lf ", hoursWorked);

    if (hoursWorked < 40)
        grossPayrate = payrate * hoursWorked;

    else (hoursWorked > 40)
        grossPayrate = payrate * hoursWorked * 1.5;
   
    printf("The total gross pay is %.2lf ", grossPayrate);



    system("pause");
}

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

int main()

{

double payrate, hoursWorked, grossPayrate=0;

printf("Enter your payrate: ");

scanf("%lf", &payrate);

printf("Enter how many hours you've worked: ");

scanf("%lf", &hoursWorked);

printf("Your payrate per hour is %.2lf ", payrate);

printf("You've worked %.2lf ", hoursWorked);

if(hoursWorked < 0 || payrate < 0)

printf("please enter valid data ");

else if (hoursWorked <= 40)

grossPayrate = payrate * hoursWorked;

else if(hoursWorked > 40)

grossPayrate = payrate*40 + payrate * (hoursWorked -40) * 1.5;

  

printf("grossPayrate = %.2lf ",grossPayrate);

return 0;

}