C Program to calculate the salesmen salary with macro functions.


Problem

A laptop manufacturing company has the monthly compensation policy for their salespersons as mentioned below −

Minimum base salary: 3000.00

Bonus for every computer sold: 200.00

Commission on the total monthly sales: 5 per cent

Since the prices of laptops are changing, the sales price of each laptop is fixed at the beginning of every month.

Solution

The logic for finding the bonus and commission is as follows −

bonus = BONUS_RATE * quantity ;
commission = COMMISSION * quantity * price ;

The gross salary is calculated by using the formula given below −

Gross salary = basic salary + (quantity * bonus rate)
+ (quantity * Price) * commission rate

Example

Following is the C program to calculate the salesmen salary by using the macro functions −

 Live Demo

#define BASIC_SALARY 3000.00
#define BONUS_RATE 200.00
#define COMMISSION 0.05
main(){
   int quantity ;
   float gross_salary, price ;
   float bonus, commission ;
   printf("number of items sold and their price
") ;    scanf("%d %f", &quantity, &price) ;    bonus = BONUS_RATE * quantity ;    commission = COMMISSION * quantity * price ;    gross_salary = BASIC_SALARY + bonus + commission ;    printf("
");    printf("Bonus = %6.2f
", bonus) ;    printf("Commission = %6.2f
", commission) ;    printf("Gross salary = %6.2f
", gross_salary) ; }

Output

When the above program is executed, it produces the following output −

Number of items sold and their price
20 150000
Bonus = 4000.00
Commission = 150000.00
Gross salary = 157000.00

Updated on: 25-Mar-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements