Question

A salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been wi

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

#include <stdio.h>

// calculateBonus() function calculates the bonus based on the years worked
int calculateBonus(int yearsWorked) {
    const int higherBonusLimit = 5;         // more than 5 years limit for bonus of $20
    const int higherBonus = 20;             // $20 bonus
    const int lowerBonus = 10;              // $10 bonus

    int bonus = 0;                          // the bonus calculated will be stored here
    if (yearsWorked <= higherBonusLimit) {
        bonus = yearsWorked * lowerBonus;
    } else {
        bonus = yearsWorked * higherBonus;
    }

    return bonus;
}

// calculateAdditionalBonus() function calculates the bonus based on the total sales made
double calculateAdditionalBonus(double totalSales) {
    const double lowerCommission = 0.03;    // percentage of commission for sales range ($5000, $10000)
    const double higherCommission = 0.06;   // percentage of commission for sales atleast worth $10000

    double additionalBonus = 0;             // additional bonus calculated will be stored here
    if (totalSales >= 5000 && totalSales < 10000) {
        additionalBonus = totalSales * lowerCommission;
    } else if (totalSales >= 10000) {
        additionalBonus = totalSales * higherCommission;
    }

    return additionalBonus;
}

// userContinue() function prompts the user whether to continue or not and handles exceptions
int userContinue() {
    while (1) {
        printf("\n\nDo you wish to continue? (y / n) ");
        char choice = 0;
        do {
            scanf("%c", &choice);
        } while (choice == '\n');

        if (choice == 'y' || choice == 'Y') {
            return 1;
        } else if (choice == 'n' || choice == 'N') {
            return 0;
        }

        printf("Invalid Choice!\n");
    }
}

void formatAndPrint(double monthlySalary, double totalBonus, double totalSalary) {
    // Please format your output in this function
    printf("Base Salary: %.2lf\n", monthlySalary);
    printf("Bonus: %.2lf\n", totalBonus);
    printf("Total Salary: %.2lf", totalSalary);
}

int main() {
    double monthlySalary = 0;
    int yearsWorked = 0;
    double totalSales = 0;

    while (1) {

        // loop untill a valid monthly salary is entered
        while (1) {
            printf("Enter monthly salary: ");
            scanf("%lf", &monthlySalary);

            if (monthlySalary > 0 && monthlySalary < 1500) {
                break;
            }
            printf("Invalid Salary!\n");
        }

        // loop until a valid years worked is entered
        while (1) {
            printf("Enter years worked: ");
            scanf("%d", &yearsWorked);

            if (yearsWorked > 0 && yearsWorked < 40) {
                break;
            }
            printf("Invalid worked years!\n");
        }

        // loop until a valid total sales is entered
        while (1) {
            printf("Enter total sales made: ");
            scanf("%lf", &totalSales);

            if (totalSales > 0) {
                break;
            }
            printf("Invalid sales made!\n");
        }

        // totalBonus = bonus due to yeard worked + bonus due to total sales
        double totalBonus = calculateBonus(yearsWorked) + calculateAdditionalBonus(totalSales);
        double totalSalary = monthlySalary + totalBonus;

        formatAndPrint(monthlySalary, totalBonus, totalSalary);

        if (!userContinue()) {
            break;
        }
    }

    return 0;
}

OUTPUT:

ajayrajs-MacBook-Air:Chegg Ajay$ gcc sales.c ajayrajs-MacBook-Air:Chegg Ajay$ ./a.out Enter monthly salary: 1003 Enter years

NOTE:

The format of the output is not specified in the question (or part of the question) posted here.
Please edit the code in the function formatAndPrint() to format your output as per your requirements.

Add a comment
Know the answer?
Add Answer to:
A salesperson also receives a bonus at the end of each month, based on the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Write a Bonus Calculator for a company. Program asks user to enter sales in...

    in python Write a Bonus Calculator for a company. Program asks user to enter sales in a month separated by commas. Program asks years of experience • If salesperson have total sales greater than 200,000 dollars he/she will get 5% bonus between 100,000 and 200,000 dollars and greater than 10 years of experience he/she will get 4% bonus - between 100,000 and 200,000 dollars and less than 10 years of experience he/she will get 3% bonus • less than than...

  • Need help on the formula for this pls Each month if a salesperson equals or exceeds a 12% commission target, they receive an additional bonus of $1,250 and Insert a column for each month to determine...

    Need help on the formula for this pls Each month if a salesperson equals or exceeds a 12% commission target, they receive an additional bonus of $1,250 and Insert a column for each month to determine if the salesperson will receive the bonus and This can be achieved by combining an If and a Vlookup statement Need help on the formula Sheet 1 Breeze Appliance Date: 12/05/2019 Branch Commission Target 12% Additional Bonus $1,250.00 Salesperson Jan Jan Bonus Feb Feb...

  • (Java) Please include one data type class and one driver class in the program. Please also...

    (Java) Please include one data type class and one driver class in the program. Please also include a UML diagram and pseudocode. B. REQUIREMENT STATEMENT THIS LAB REQUIRES OBJECT ORIENTED PROGRAMMING. YOU HAVE TO CREATE ONE DATA TYPE CLASS AND ONE DRIVER CLASS (include main) One company request an application that allows users to READ from the keyboard the information of a vendor: name (String), id (String), sale amount in the month (double) then calculate the salary of vendors based...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • JAVA. Write a Java program that accepts the total amount of cars sold and total sales...

    JAVA. Write a Java program that accepts the total amount of cars sold and total sales amount of a car salesperson for a given month. The salesperson’s paycheck is computed as follows: a. Every sales person gets 10% (commission) of total sales b. Sales totals greater than $50,000 get 5% of total sales amount c. 8 or more cars sold earns the salesperson an extra 3% Please remove 30% (taxes) of the gross pay and list the paycheck amount. Your...

  • #3: Frank's Factories has a staff of sales people like Anthony, who receives a monthly salary...

    #3: Frank's Factories has a staff of sales people like Anthony, who receives a monthly salary of $2,750.00 plus an incremental commission based on the table below. If he sells $27,300.00, what is his total gross pay for the month? Sales Volume 8,201-15,000 Over 15.000 Commission Rate 4.1% Level 1 2 6,800 12,300 1,6% Jessica has a job making baskets. Last week she made a total of 226 baskets. Calculate her gross pay if she is paid on the following...

  • Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for...

    Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for user input using a while (or while/do) loop nicely formatted output report with printf and format strings multiple input data sets using a while (or while/do) loop named constants PROJECT OVERVIEW This project provides a detailed payroll report for the sales staff at TheLaptopShop. The company has 3 tiers of salespeople: low, middle, high (designated by L, M, H) – based on their past...

  • Question 1 (25 points) Your company has a market share of 25%. The total market size...

    Question 1 (25 points) Your company has a market share of 25%. The total market size is $100 million. Your contribution margin (the ratio of the contribution per unit over the price per unit) is 20%. Your variable cost is $16 per unit. You are thinking of hiring 10 more salespeople. The annual cost per salesperson (including salary and benefits) is $120,000. In addition, each salesperson receives as a bonus 10% of the sales he or she generates. How much...

  • Show Me The Money. (15 points) Write a C++ program that calculates how much a person...

    Show Me The Money. (15 points) Write a C++ program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on, with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was...

  • Your professor is hoping to get a summer job flipping burgers at the local burger joint....

    Your professor is hoping to get a summer job flipping burgers at the local burger joint. His starting salary will be $7.25 per hour. However, there are certain incentives to encourage him to work extra hours. It is calculated as follows per day: •$7.25 for the first 6 hours he works per day, Monday through Friday .•$8.25 for the next 2 hours he works per day, Monday through Friday. •$11.25 for each hour he works over 8 hours in a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT