What's new

C# Help

Rojen G Embate

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

C language​

1. Payroller​

by CodeChum Admin
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! I can help you with that.

To solve this problem, you can use a combination of if-else statements and nested if-else statements to compute the salary based on the input provided by the user.

Here's a possible solution in C language:

C:
#include <stdio.h>

int main() {
    int yearsOfWork;
    char kindOfWork;
    int salary;

    printf("Enter years of work: ");
    scanf("%d", &yearsOfWork);
    printf("Enter kind of work (B or 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 kind of work entered. Please try again.\n");
        return 0;
    }

    printf("Salary: %d\n", salary);

    return 0;
}

In this solution, we first prompt the user to enter the years of work and the kind of work (B or W). Then, we use if-else statements and nested if-else statements to determine the salary based on the given inputs. Finally, we display the calculated salary to the user.

I hope this helps! Let me know if you have any further questions.
 
Sure! I can help you with that.

To solve this problem, you can use a combination of if-else statements and nested if-else statements to compute the salary based on the input provided by the user.

Here's a possible solution in C language:

C:
#include <stdio.h>

int main() {
    int yearsOfWork;
    char kindOfWork;
    int salary;

    printf("Enter years of work: ");
    scanf("%d", &yearsOfWork);
    printf("Enter kind of work (B or 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 kind of work entered. Please try again.\n");
        return 0;
    }

    printf("Salary: %d\n", salary);

    return 0;
}

In this solution, we first prompt the user to enter the years of work and the kind of work (B or W). Then, we use if-else statements and nested if-else statements to determine the salary based on the given inputs. Finally, we display the calculated salary to the user.

I hope this helps! Let me know if you have any further question

Sure! I can help you with that.

To solve this problem, you can use a combination of if-else statements and nested if-else statements to compute the salary based on the input provided by the user.

Here's a possible solution in C language:

C:
#include <stdio.h>

int main() {
    int yearsOfWork;
    char kindOfWork;
    int salary;

    printf("Enter years of work: ");
    scanf("%d", &yearsOfWork);
    printf("Enter kind of work (B or 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 kind of work entered. Please try again.\n");
        return 0;
    }

    printf("Salary: %d\n", salary);

    return 0;
}

In this solution, we first prompt the user to enter the years of work and the kind of work (B or W). Then, we use if-else statements and nested if-else statements to determine the salary based on the given inputs. Finally, we display the calculated salary to the user.

I hope this helps! Let me know if you have any further questions.
c language

2. Ask the Pocket Money​

by CodeChum Admin
Ask the user to input their current pocket money.
If the number they inputted is valid (i.e. non-negative), print the amount.

Also, check if the amount they inputted ends with 7. If it does, print "Such lucky money!", otherwise, print "Just normal money.".
If the amount they inputted is negative, print "Stop lying, tell me what's in your pocket!"

Sample Output 1
Enter current pocket money: 27
27
Such lucky money!
Sample Output 2
Enter current pocket money: 100
100
Just normal money.
Sample Output 3
Enter current pocket money: -25
Stop lying, tell me what's in your pocket!
 
Sure! I can help you with that.

To solve this problem, you can use if-else statements and conditions to check the validity of the inputted pocket money and determine whether it ends with 7.

Here's a possible solution in C language:

C:
#include <stdio.h>

int main() {
    int pocketMoney;

    printf("Enter current pocket money: ");
    scanf("%d", &pocketMoney);

    if (pocketMoney >= 0) {
        printf("%d\n", pocketMoney);
        if (pocketMoney % 10 == 7) {
            printf("Such lucky money!\n");
        } else {
            printf("Just normal money.\n");
        }
    } else {
        printf("Stop lying, tell me what's in your pocket!\n");
    }

    return 0;
}

In this solution, we first prompt the user to enter their current pocket money. Then, we use if-else statements and conditions to check if the pocket money is valid (non-negative) and whether it ends with 7. If the pocket money is valid, we print the amount, and if it ends with 7, we print "Such lucky money!", otherwise, we print "Just normal money.". If the pocket money is negative, we print "Stop lying, tell me what's in your pocket!".

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

c language

2. Ask the Pocket Money​

by CodeChum Admin
Ask the user to input their current pocket money.
If the number they inputted is valid (i.e. non-negative), print the amount.

Also, check if the amount they inputted ends with 7. If it does, print "Such lucky money!", otherwise, print "Just normal money.".
If the amount they inputted is negative, print "Stop lying, tell me what's in your pocket!"

Sample Output 1
Enter current pocket money: 27
27
Such lucky money!
Sample Output 2
Enter current pocket money: 100
100
Just normal money.
Sample Output 3
Enter current pocket money: -25
Stop lying, tell me what's in your pocket!
Sure! Here's a solution in C language to solve the "Ask the Pocket Money" problem:

C:
#include <stdio.h>

int main() {
    int pocketMoney;

    printf("Enter current pocket money: ");
    scanf("%d", &pocketMoney);

    if (pocketMoney >= 0) {
        printf("%d\n", pocketMoney);
        
        if (pocketMoney % 10 == 7) {
            printf("Such lucky money!\n");
        } else {
            printf("Just normal money.\n");
        }
    } else {
        printf("Stop lying, tell me what's in your pocket!\n");
    }

    return 0;
}

In this solution, we first prompt the user to input their current pocket money. We then use an if-else statement to check if the pocket money is greater than or equal to 0 (non-negative). If it is, we print the amount.

Next, we use another if-else statement to check if the pocket money ends with 7. We do this by checking if the remainder of dividing the pocket money by 10 is equal to 7. If it is, we print "Such lucky money!". Otherwise, we print "Just normal money.".

If the pocket money is negative, we print "Stop lying, tell me what's in your pocket!".

I hope this helps! Let me know if you have any further questions.
 
Sure! I can help you with that.

To solve this problem, you can use if-else statements and conditions to check the validity of the inputted pocket money and determine whether it ends with 7.

Here's a possible solution in C language:

C:
#include <stdio.h>

int main() {
    int pocketMoney;

    printf("Enter current pocket money: ");
    scanf("%d", &pocketMoney);

    if (pocketMoney >= 0) {
        printf("%d\n", pocketMoney);
        if (pocketMoney % 10 == 7) {
            printf("Such lucky money!\n");
        } else {
            printf("Just normal money.\n");
        }
    } else {
        printf("Stop lying, tell me what's in your pocket!\n");
    }

    return 0;
}

In this solution, we first prompt the user to enter their current pocket money. Then, we use if-else statements and conditions to check if the pocket money is valid (non-negative) and whether it ends with 7. If the pocket money is valid, we print the amount, and if it ends with 7, we print "Such lucky money!", otherwise, we print "Just normal money.". If the pocket money is negative, we print "Stop lying, tell me what's in your pocket!".

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


Sure! Here's a solution in C language to solve the "Ask the Pocket Money" problem:

C:
#include <stdio.h>

int main() {
    int pocketMoney;

    printf("Enter current pocket money: ");
    scanf("%d", &pocketMoney);

    if (pocketMoney >= 0) {
        printf("%d\n", pocketMoney);
       
        if (pocketMoney % 10 == 7) {
            printf("Such lucky money!\n");
        } else {
            printf("Just normal money.\n");
        }
    } else {
        printf("Stop lying, tell me what's in your pocket!\n");
    }

    return 0;
}

In this solution, we first prompt the user to input their current pocket money. We then use an if-else statement to check if the pocket money is greater than or equal to 0 (non-negative). If it is, we print the amount.

Next, we use another if-else statement to check if the pocket money ends with 7. We do this by checking if the remainder of dividing the pocket money by 10 is equal to 7. If it is, we print "Such lucky money!". Otherwise, we print "Just normal money.".

If the pocket money is negative, we print "Stop lying, tell me what's in your pocket!".

I hope this helps! Let me know if you have any further questions.
C language

3. Special Name, or Age, or Birthyear?​

by CodeChum Admin
Ask the user to input their name.

If their name ends with a vowel, ask them to input their age as well.
If their age is even, print "Wow, you're special!". Otherwise, if their age is odd, ask them to input their birth year.
If their birth year is even, print "Oh, you're still special!". Otherwise, print "You will be special next year.".

If their name ends with a consonant though, print "You're awesome!" .

Sample Output 1
Enter name: Jane
Enter age: 20
Wow, you're special!
Sample Output 2
Enter name: John
You're awesome!
Sample Output 3
Enter name: Mike
Enter age: 35
Enter birth year: 1987
You will be special next year.
 
C language

3. Special Name, or Age, or Birthyear?​

by CodeChum Admin
Ask the user to input their name.

If their name ends with a vowel, ask them to input their age as well.
If their age is even, print "Wow, you're special!". Otherwise, if their age is odd, ask them to input their birth year.
If their birth year is even, print "Oh, you're still special!". Otherwise, print "You will be special next year.".

If their name ends with a consonant though, print "You're awesome!" .

Sample Output 1
Enter name: Jane
Enter age: 20
Wow, you're special!
Sample Output 2
Enter name: John
You're awesome!
Sample Output 3
Enter name: Mike
Enter age: 35
Enter birth year: 1987
You will be special next year.
Certainly! Here's a solution in C language to solve the "Special Name, or Age, or Birthyear?" problem:

C:
#include <stdio.h>
#include <string.h>

int main() {
    char name[50];
    int age, birthYear;

    printf("Enter name: ");
    scanf("%s", name);

    if (name[strlen(name) - 1] == 'a' || name[strlen(name) - 1] == 'e' || name[strlen(name) - 1] == 'i' || name[strlen(name) - 1] == 'o' || name[strlen(name) - 1] == 'u') {
        printf("Enter age: ");
        scanf("%d", &age);

        if (age % 2 == 0) {
            printf("Wow, you're special!\n");
        } else {
            printf("Enter birth year: ");
            scanf("%d", &birthYear);

            if (birthYear % 2 == 0) {
                printf("Oh, you're still special!\n");
            } else {
                printf("You will be special next year.\n");
            }
        }
    } else {
        printf("You're awesome!\n");
    }

    return 0;
}

In this solution, we first prompt the user to input their name. We then check if the last character of the name is a vowel ('a', 'e', 'i', 'o', 'u') by comparing it to each vowel individually. If it is a vowel, we proceed to ask for the age. If the age is even, we print "Wow, you're special!". If the age is odd, we ask for the birth year and check if it is even or odd to determine the final output.

If the last character of the name is not a vowel, we print "You're awesome!".

I hope this helps! Let me know if you have any further questions.
 
Certainly! Here's a solution in C language to solve the "Special Name, or Age, or Birthyear?" problem:

C:
#include <stdio.h>
#include <string.h>

int main() {
    char name[50];
    int age, birthYear;

    printf("Enter name: ");
    scanf("%s", name);

    if (name[strlen(name) - 1] == 'a' || name[strlen(name) - 1] == 'e' || name[strlen(name) - 1] == 'i' || name[strlen(name) - 1] == 'o' || name[strlen(name) - 1] == 'u') {
        printf("Enter age: ");
        scanf("%d", &age);

        if (age % 2 == 0) {
            printf("Wow, you're special!\n");
        } else {
            printf("Enter birth year: ");
            scanf("%d", &birthYear);

            if (birthYear % 2 == 0) {
                printf("Oh, you're still special!\n");
            } else {
                printf("You will be special next year.\n");
            }
        }
    } else {
        printf("You're awesome!\n");
    }

    return 0;
}

In this solution, we first prompt the user to input their name. We then check if the last character of the name is a vowel ('a', 'e', 'i', 'o', 'u') by comparing it to each vowel individually. If it is a vowel, we proceed to ask for the age. If the age is even, we print "Wow, you're special!". If the age is odd, we ask for the birth year and check if it is even or odd to determine the final output.

If the last character of the name is not a vowel, we print "You're awesome!".

I hope this helps! Let me know if you have any further questions.
Make a unique C language program
Write a c program that will ask the user to enter the length and height of a trapezoid. Find its are. Use the formula
A = ((a+b/2)*h
a = length of base 1
b = length of base 2
h = height of the trapezoid
A = area of trapezoid

Sample output 1
Enter the value of base 1: 0
Invalid value!

Sample output 2
Enter the value of base 1: 2.67
Enter the value of base 2:;-7.98
Invalid value

Sample output 3
Enter the value of base 1: 1.2345
Enter the value of base 2: 5.678
Enter the value of height: 0
Invalid value!
 
Write a c program that will ask the user to enter the length and height of a trapezoid. Find its are. Use the formula
A = ((a+b/2)*h
a = length of base 1
b = length of base 2
h = height of the trapezoid
A = area of trapezoid

Sample output 1
Enter the value of base 1: 0
Invalid value!

Sample output 2
Enter the value of base 1: 2.67
Enter the value of base 2:;-7.98
Invalid value

Sample output 3
Enter the value of base 1: 1.2345
Enter the value of base 2: 5.678
Enter the value of height: 0
Invalid value!
Certainly! Here's a C program that calculates the area of a trapezoid based on user input:

```c
#include <stdio.h>

int main() {
double base1, base2, height, area
 

Similar threads

Back
Top