What's new

C# Help c languagae programming

Rojen G Embate

Honorary Poster
Joined
Mar 12, 2018
Posts
275
Reaction
217
Points
209
Age
19

1. Payroller​

C language

Ask the user to enter their years of work as integer and their kind of work as a character:
'B' for Blue-collar worker
'W' for White-collar worker

Compute their salary based on the following table:
< 2 yrs | < 5 yrs | 5 yrs & above
B 10,000 | 12,000 | 15,000
W 20,000 | 40,000 | 75,000
Sample Output 1
Enter years of work: 1
Enter kind of work: B
Salary: 10,000
Sample Output 2
Enter years of work: 3
Enter kind of work: W
Salary: 40,000
Sample Output 3
Enter years of work: 7
Enter kind of work: B
Salary: 15,000
 
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.
 
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.

1. Payroller​

C language

CODECHUMP

Ask the user to enter their years of work as integer and their kind of work as a character:
'B' for Blue-collar worker
'W' for White-collar worker

Compute their salary based on the following table:
< 2 yrs | < 5 yrs | 5 yrs & above
B 10,000 | 12,000 | 15,000
W 20,000 | 40,000 | 75,000
Sample Output 1
Enter years of work: 1
Enter kind of work: B
Salary: 10,000
Sample Output 2
Enter years of work: 3
Enter kind of work: W
Salary: 40,000
Sample Output 3
Enter years of work: 7
Enter kind of work: B
Salary: 15,000
 

1. Payroller​

C language

CODECHUMP

Ask the user to enter their years of work as integer and their kind of work as a character:
'B' for Blue-collar worker
'W' for White-collar worker

Compute their salary based on the following table:
< 2 yrs | < 5 yrs | 5 yrs & above
B 10,000 | 12,000 | 15,000
W 20,000 | 40,000 | 75,000
Sample Output 1
Enter years of work: 1
Enter kind of work: B
Salary: 10,000
Sample Output 2
Enter years of work: 3
Enter kind of work: W
Salary: 40,000
Sample Output 3
Enter years of work: 7
Enter kind of work: B
Salary: 15,000
Certainly! Here's the revised code for 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 declare the necessary variables to store the years of work, kind of work, and salary.
2. The program prompts the user to enter the years of work and kind of work using printf and scanf functions.
3. Based on the user's input, the program uses an if-else statement to calculate the salary using the provided table.
4. The calculated salary is then printed using printf.

The program takes user input for the years of work and kind of work, calculates the corresponding salary based on the table, and displays the result.

I hope this helps! Let me know if you have any further questions.
 
Back
Top