Sure! Here's a solution to the Payroller program in C:
C:
#include <stdio.h>
int main() {
int yearsOfWork;
char kindOfWork;
int salary;
printf("Enter years of work: ");
scanf("%d", &yearsOfWork);
getchar(); // To consume the newline character
printf("Enter kind of work (B/W): ");
scanf("%c", &kindOfWork);
if (kindOfWork == 'B') {
if (yearsOfWork < 2) {
salary = 10000;
} else if (yearsOfWork < 5) {
salary = 12000;
} else {
salary = 15000;
}
} else if (kindOfWork == 'W') {
if (yearsOfWork < 2) {
salary = 20000;
} else if (yearsOfWork < 5) {
salary = 40000;
} else {
salary = 75000;
}
} else {
printf("Invalid input for kind of work.\n");
return 0;
}
printf("Salary: %d\n", salary);
return 0;
}
Explanation:
1. We start by declaring the necessary variables to store the years of work, kind of work, and salary.
2. We prompt the user to enter the years of work and kind of work by using
printf
and
scanf
functions.
3. Based on the user's input, we use an if-else statement to calculate the salary using the provided table.
4. We print the calculated salary using
printf
.
The program takes the user's input for the years of work and kind of work, and then calculates and displays the corresponding salary based on the table provided.
I hope this helps! Let me know if you have any further questions.