C basic programming: (2) Calculate the bonus based on the profit

Source: Internet
Author: User

Question: The bonus paid by an enterprise is based on the profit.

If the profit is lower than or equal to 0.1 million yuan, the bonus can be increased by 10%;

If the profit is higher than 0.1 million RMB, if the profit is lower than 0.2 million RMB, the Commission for the portion lower than 0.1 million RMB is 10%. If the profit is higher than 0.1 million RMB, the Commission is 7.5%;

The amount between 0.2 million and 0.4 million is higher than 0.2 million RMB, which can be increased to 5%;

The amount between 0.4 million and 0.6 million is higher than that of 0.4 million yuan, which can be increased to 3%;

The amount between 0.6 million and 1 million is higher than 0.6 million RMB, which can be increased to 1.5%;

When the price is 1 million yuan, the percentage of the price exceeding 1 million Yuan is 1% yuan. input the profit for the current month from the keyboard, and ask for the total number of bonuses to be paid?

Program Analysis: Use the number axis to split and locate. Note that the bonus should be defined as an integer or a long integer.

#include "stdio.h"int main() {int profit;printf("Please input the profit number and kick the Enter: \n");scanf("%d", &profit);int bonus = CountBonus(profit);printf("profit: %d,  bonus: %d\n", profit, bonus);return 0;}int CountBonus(int profit) {int flag, bonus = 0, bonus0, bonus1, bonus2, bonus4, bonus6, bonus10;flag = profit/100000;bonus1 = bonus  + 100000 * 0.1;bonus2 = bonus1 + 100000 * 0.75;bonus4 = bonus2 + 200000 * 0.5;bonus6 = bonus4 + 200000 * 0.3;bonus10= bonus6 + 200000 * 0.15;switch(flag) {case 0 : bonus = bonus1;break;case 1 : bonus = bonus1 + (profit - 100000) * 0.75;break;case 2 :case 3 :bonus = bonus2 + (profit - 200000) * 0.5;break;case 4 :case 5 : bonus = bonus4 + (profit - 400000) * 0.3;break;case 6 : case 7 : case 8 : case 9 :bonus = bonus6 + (profit - 600000) * 0.15;break;default: bonus = bonus10 + (profit - 1000000) * 0.1;break;}return bonus;}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.