ĿǰΪֹдij...Ȼܼ...
룺
/* д, ҪһеĹСʱ,Ȼӡܶ,˰Լ * ¼: * a. ʵȼ ʹswitchѡʵȼ * 1. 8.75Ԫ/Сʱ * 2. 9.33Ԫ/Сʱ * 3. 10.00Ԫ/Сʱ * 4. 11.20Ԫ/Сʱ * b. Ӱ (40Сʱ) = 1.5 ʱ * c. ˰ * ǰ300ԪΪ15% һ 150 ԪΪ20% µΪ25% */ /*Ŀ: ӡܶ,˰, */ /* : ûʵȼ жǷЧ Ч:(ؼ) Ч: ûÿܹСʱ жǷ () : ʵȼ * Сʱ Ӱ : + ((Сʱ - 40) * 1.5) ܹ = + Ӱ ˰: 0 < ܹ < 300, ˰: ܹ * 0.15 300 < ܹ < 450 һ˰: ˰ + (ܹ - 300) * 0.20 ܹ > 450 : ˰ + һ˰ + (ܹ - 450) * 0.25 ӡ ܶ, ˰ , */ #include <stdio.h> #define BASE_T 40 //ʱ #define OVER_T 1.5F //Ӱʱ䱶 #define RATE1 0.15F //һ˰ #define RATE2 0.20F //ڶ˰ #define RATE3 0.25F //˰ #define TAX1 300 //ڶ˰ #define TAX2 450 //˰ #define BASE_TAX1 (TAX1 * RATE1) //һ˰ֵ #define BASE_TAX2 ((TAX2-TAX1) * RATE2) //ڶ˰ֵ void menu(void); int main(void) { float salary; //ܶ float tax; //˰ int hour; //ÿܹСʱ char select; //˵ѡ float BASE_D; //ÿСʱ int flag = 1; menu(); //ӡ˵ while(flag) { select = getchar(); while(getchar() != '\n') //ջ continue; switch(select) //ѡ˰ { case '1':BASE_D = 8.75F; break; case '2':BASE_D = 9.33F; break; case '3':BASE_D = 10.00F; break; case '4':BASE_D = 11.20F; break; case '5':flag = 5; break; default:flag = 0; } if(flag == 5) break; //ѡ 5 ˳ if(!flag) { flag = 1; printf("Please enter a number between 1~5 : "); continue; } printf("Input the weekly working time(hours): "); while(scanf("%d", &hour) != 1) //ûÿܹʱ { printf("Invalid character.\nPlease enter a number: "); // while(getchar() != '\n') //ջ continue; } salary = 0; //ܶ tax = 0; //˰ if(hour < BASE_T) //ʱС40Сʱ salary += hour * BASE_D; else //ʱ40Сʱ, 40Сʱ + 40СʱֵĹ salary += BASE_D * BASE_T + ((hour - BASE_T) * OVER_T) * BASE_D; if(salary <= TAX1) //ܹ300, Ӧ˰ tax += salary * RATE1; else if(salary <= TAX2) //ܹ300~450֮, Ӧ˰ tax += BASE_TAX1 + (salary - TAX1) * RATE2; else tax += BASE_TAX1 + BASE_TAX2 + (salary - TAX2) * RATE3; //ܹʳ450, Ӧ˰ printf("ܶ: %10.2f\n˰ : %10.2f\n : %10.2f\n", salary, tax, salary - tax); while(getchar() != '\n') //ջ continue; menu(); //μ,´ӡ˵ } printf("\nBye~"); return 0; } void menu(void) { printf("*****************************************************************\n"); printf("Enter the number corresponding to the desired pay rate or action:\n"); printf("1) $8.75/hr 2) $9.33/hr\n"); printf("3) $10.00/hr 4) $11.20/hr\n"); printf("5) quit\n"); printf("*****************************************************************\n"); printf("Please select(1 ~ 5): "); }
[ Ryker 2013-5-3 17:44 ༭ ]