Home > Backend Development > C++ > C program uses macro function to calculate salesperson's salary

C program uses macro function to calculate salesperson's salary

WBOY
Release: 2023-09-10 18:13:02
forward
770 people have browsed it

C program uses macro function to calculate salespersons salary

Question

The monthly compensation policy of a laptop manufacturing company for its sales staff is as follows -

Minimum basic salary: 3000.00

Bonus per computer sold: 200.00

Commission on total monthly sales: 5%

Since the price of laptops is constantly changing, the sales price of each laptop The beginning of the month is fixed every month.

Solution

The logic to find bonus and commission is as follows-

bonus = BONUS_RATE * quantity ;
commission = COMMISSION * quantity * price ;
Copy after login

The total salary is calculated using the formula given below-

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

Example

The following is a C program that uses macro functions to calculate sales staff wages-

Live demonstration

#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</p><p>") ;
   scanf("%d %f", &quantity, &price) ;
   bonus = BONUS_RATE * quantity ;
   commission = COMMISSION * quantity * price ;
   gross_salary = BASIC_SALARY + bonus + commission ;
   printf("</p><p>");
   printf("Bonus = %6.2f</p><p>", bonus) ;
   printf("Commission = %6.2f</p><p>", commission) ;
   printf("Gross salary = %6.2f</p><p>", gross_salary) ;
}
Copy after login

Output

When the above program is executed, the following output will be produced-

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

The above is the detailed content of C program uses macro function to calculate salesperson's salary. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template