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:
Your goal is to implement this program in C and provide a clear, well-documented solution.
Algorithm
Input:
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.
Calculate Taxes:
Calculate Net Pay:
Output:
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.
Last modified: 25 February 2024