Program: Weekly Pay Calculation

Instructions

In this programming assignment, you are tasked with creating a C program that calculates the weekly pay of an employee. The program should prompt the user to input the number of hours worked in a week via the keyboard. The output should display the gross pay, taxes, and net pay. Assumptions for the calculations are as follows:

  • Basic pay rate: $12.00 per hour.

  • Overtime (in excess of 40 hours): Time and a half.

  • Tax rates:

    • 15% of the first $300.

    • 20% of the next $150.

    • 25% of the rest.

Your goal is to implement this program in C and provide a clear, well-documented solution.

Algorithm

  1. Input:

    • Prompt the user to enter the number of hours worked in a week.

  2. Calculate Gross Pay:

    • If the hours worked are less than or equal to 40, calculate the gross pay using the basic pay rate.

    • If the hours worked exceed 40, calculate the gross pay with time and a half for overtime.

  3. Calculate Taxes:

    • Determine the tax amount based on different income thresholds and tax rates.

  4. Calculate Net Pay:

    • Subtract the calculated taxes from the gross pay to obtain the net pay.

  5. Output:

    • Display the Weekly Payroll Summary, including Gross Pay, Taxes, and Net Pay.

Pseudocode

CONSTANTS:
    basicPayRate = 12.00
    overtimeRate = 1.5
    taxRate1 = 0.15
    taxRate2 = 0.20
    taxRate3 = 0.25
    taxThreshold1 = 300.0
    taxThreshold2 = 150.0

VARIABLES:
    hoursWorked, grossPay, taxes, netPay

INPUT:
    Prompt user to enter hoursWorked

CALCULATE GROSS PAY:
    IF hoursWorked <= 40:
        grossPay = hoursWorked * basicPayRate
    ELSE:
        grossPay = (40 * basicPayRate) + ((hoursWorked - 40) * basicPayRate * overtimeRate)

CALCULATE TAXES:
    IF grossPay <= taxThreshold1:
        taxes = grossPay * taxRate1
    ELSE IF grossPay <= (taxThreshold1 + taxThreshold2):
        taxes = (taxThreshold1 * taxRate1) + ((grossPay - taxThreshold1) * taxRate2)
    ELSE:
        taxes = (taxThreshold1 * taxRate1) + (taxThreshold2 * taxRate2) + ((grossPay - taxThreshold1 - taxThreshold2) * taxRate3)

CALCULATE NET PAY:
    netPay = grossPay - taxes

OUTPUT:
    Display Weekly Payroll Summary:
        Gross Pay: grossPay
        Taxes: taxes
        Net Pay: netPay

Program

#include <stdio.h>

int main() {
    // Constants
    const float basicPayRate = 12.00;
    const float overtimeRate = 1.5;
    const float taxRate1 = 0.15;
    const float taxRate2 = 0.20;
    const float taxRate3 = 0.25;
    const float taxThreshold1 = 300.0;
    const float taxThreshold2 = 150.0;

    // Variables
    float hoursWorked, grossPay, taxes, netPay;

    // Input: Get the number of hours worked
    printf("Enter the number of hours worked in a week: ");
    scanf("%f", &hoursWorked);

    // Calculate gross pay
    if (hoursWorked <= 40) {
        grossPay = hoursWorked * basicPayRate;
    } else {
        grossPay = 40 * basicPayRate + (hoursWorked - 40) * basicPayRate * overtimeRate;
    }

    // Calculate taxes
    if (grossPay <= taxThreshold1) {
        taxes = grossPay * taxRate1;
    } else if (grossPay <= (taxThreshold1 + taxThreshold2)) {
        taxes = taxThreshold1 * taxRate1 + (grossPay - taxThreshold1) * taxRate2;
    } else {
        taxes = taxThreshold1 * taxRate1 + taxThreshold2 * taxRate2 + (grossPay - taxThreshold1 - taxThreshold2) * taxRate3;
    }

    // Calculate net pay
    netPay = grossPay - taxes;

    // Output: Display the results
    printf("\nWeekly Payroll Summary:\n");
    printf("Gross Pay: $%.2f\n", grossPay);
    printf("Taxes: $%.2f\n", taxes);
    printf("Net Pay: $%.2f\n", netPay);

    return 0;
}

This C program calculates weekly pay based on the provided requirements and displays the results in a structured format.