![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
#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
Advertisements