# C Program to calculate the salesmen salary with macro functions.

CServer Side ProgrammingProgramming

## 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\n") ;
scanf("%d %f", &quantity, &price) ;
bonus = BONUS_RATE * quantity ;
commission = COMMISSION * quantity * price ;
gross_salary = BASIC_SALARY + bonus + commission ;
printf("\n");
printf("Bonus = %6.2f\n", bonus) ;
printf("Commission = %6.2f\n", commission) ;
printf("Gross salary = %6.2f\n", 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 11:18:21