Write a program that calculates Net Pay. It should do this by calling a function
ID: 3551261 • Letter: W
Question
- Write a program that calculates Net Pay. It should do this by calling a function called CalNetPay that calculates and returns Net Pay when given the hours worked and the hourly pay rate. The main function should pass the hours worked and pay rate to the function CalNetPay. The main function should get the hours worked and pay rates from a file called Lab12aInput.txt that you will create. From the main function print to an output file called Lab12Output.txt the Net Pay for each record in the Input file.
- Lab12aInput should contain the following lines.
- 2 10.5
- 5 20
- 10 30.2
- Your program should open the Input file and make sure the open was successful.
- Your program should use a while Loop to process and read the data from the Input file. The while loop should continue execution as long as values are read from the file
Explanation / Answer
#include <stdio.h>
int main() {
float basic, hra, da, ma, pf, insurance, net, gross;
/* get the salary inputs from the user */
printf("Enter your basic salary:");
scanf("%f", &basic);
printf("House Rent Allowance: ");
scanf("%f", &hra);
printf("Dearness Allowance:");
scanf("%f", &da);
printf("Medical Allowance:");
scanf("%f", &ma);
printf("Provident Fund and Insurance amount:");
scanf("%f%f", &pf, &insurance);
/* gross salary calculation */
gross = basic + (hra * basic) / 100 + (da * basic) / 100;
gross = gross + (ma * basic) / 100;
/* net salary calculation */
net = gross - (pf + insurance);
/* print the salary slip */
printf(" Salary Slip: ");
printf("Basic Salary: %.2f ", basic);
printf("House Rent Allowance: %.2f ", hra);
printf("Dearness Allowance: %.2f ", da);
printf("Medical Allowance: %.2f ", ma);
printf(" Gross Salary: %.2f Rupees ", gross);
printf(" Deductions: ");
printf("Provident fund: %.2f ", pf);
printf("Insurance: %.2f ", insurance);
printf(" Net Salary: %.2f Rupees ", net);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.