C语言入门 -- 打印工资总额、税金及净工资(2020/12/11)

打印工资

已知基本工资率、加班费计算及税率,打印工资总额、税金及净工资

假设如下:
(1) 基本工资率=每小时应支付美元,例如10美元/小时
(2) 加班(每周超过40小时)=(基本工资率)*2.5
(3) 税率:

  • 前300美元的15%;
  • 下一笔150美元的20%;
  • 剩下的25%

编写一个程序,首先显示一个支付率菜单,从中选择:


输入与所需付薪率或操作相对应的数字:
1) 8.75美元/小时
2)9.33美元/小时
3) 10.00美元/小时
4)11.20美元/小时
5) 退出


使用Scanf(“%d”,&choice)获取用户的选择,使用开关(choice)选择支付率。
(1) 如果选择了选项1到4,程序应请求工作小时数;
(2) 程序应循环使用,直到输入5;
(3) 如果输入的不是选项1到5,程序应该提醒用户正确的选择是什么,然后循环使用。
最后,程序应该打印工资总额、税金和净工资。

/*
  Name:programme3.c
  Author:祁麟
  copyright:BJTU | school of software 2004
  Date:2020/10/13 
  Description:prints the gross pay, the taxes, and the net pay.
*/

#include 
#define PayRate1 8.75
#define PayRate2 9.33
#define PayRate3 10.00
#define PayRate4 11.20
#define TaxRate1 0.15
#define TaxRate2 0.20
#define TaxRate3 0.25

int main (){
     
	
	int choice,hour;
	float GrossPay,tax,NetPay;
	
	printf ("*****************************************************************\n");
	printf ("Enter the number corresponding to the desired pay rate or action:\n");
	printf ("1) $8.75/hr                   ");
	printf ("2) $9.33/hr\n");
	printf ("3) $10.00/hr                  ");
	printf ("4) $11.20/hr\n");
	printf ("5) quit\n");
	printf ("*****************************************************************\n");
		
	while (1){
     
		scanf ("%d",&choice);		    
		
		if (choice == 5) break;
		
		switch (choice) {
     
			case 1:
				printf ("Please enter the hours worked:");
		        scanf ("%d",&hour);
					
				if (hour<=40){
     
					GrossPay = PayRate1*hour;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}
				else {
     
					GrossPay = PayRate1*40+ PayRate1*(hour-40)*2.5;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}	
					
				if (GrossPay<=300){
     
					tax = GrossPay * TaxRate1 ;
					printf ("The tax is:      %.2f\n",tax);
				}
				else if (GrossPay>300&&GrossPay<=450){
     
					tax = TaxRate1*300+ (GrossPay - 300)*TaxRate2;
					printf ("The tax is:      %.2f\n",tax);
				}
				else {
     
					tax = TaxRate1*300+ TaxRate2*150+ (GrossPay-450.0)*TaxRate3;
					printf ("The tax is:      %.2f\n",tax);
				}
				NetPay = GrossPay - tax;
				printf ("The net pay is:  %.2f\n\n",NetPay);
				printf ("Enter the number corresponding to the desired pay rate or action:\n");
				break;
				
			case 2:
				printf ("Please enter the hours worked:");
		        scanf ("%d",&hour);
					
				if (hour<=40){
     
					GrossPay = PayRate2*hour;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}
				else {
     
					GrossPay = PayRate2*40+ PayRate2*(hour-40)*2.5;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}	
					
				if (GrossPay<=300){
     
					tax = GrossPay*TaxRate1;
					printf ("The tax is:      %.2f\n",tax);
				}
				else if (GrossPay>300&&GrossPay<=450){
     
					tax = TaxRate1*300+ (GrossPay - 300)*TaxRate2;
					printf ("The tax is:      %.2f\n",tax);
				}
				else {
     
					tax = TaxRate1*300+ TaxRate2*150+ (GrossPay-450)*TaxRate3;
					printf ("The tax is:      %.2f\n",tax);
				}
				NetPay = GrossPay - tax;
				printf ("The net pay is:  %.2f\n\n",NetPay);
				printf ("Enter the number corresponding to the desired pay rate or action:\n");
				break;
				
			case 3:
				printf ("Please enter the hours worked:");
		        scanf ("%d",&hour);
					
				if (hour<=40){
     
					GrossPay = PayRate3*hour;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}
				else {
     
					GrossPay = PayRate3*40+ PayRate3*(hour-40)*2.5;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}	
					
				if (GrossPay<=300){
     
					tax = GrossPay*TaxRate1;
					printf ("The tax is:      %.2f\n",tax);
				}
				else if (GrossPay>300&&GrossPay<=450){
     
					tax = TaxRate1*300+ (GrossPay - 300)*TaxRate2;
					printf ("The tax is:      %.2f\n",tax);
				}
				else {
     
					tax = TaxRate1*300+ TaxRate2*150+ (GrossPay-450)*TaxRate3;
					printf ("The tax is:      %.2f\n",tax);
				}
				NetPay = GrossPay - tax;
				printf ("The net pay is:  %.2f\n\n",NetPay);
				printf ("Enter the number corresponding to the desired pay rate or action:\n");
				break;
			
			case 4:
				printf ("Please enter the hours worked:");
		        scanf ("%d",&hour);
					
				if (hour<=40){
     
					GrossPay = PayRate4*hour;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}
				else {
     
					GrossPay = PayRate4*40+ PayRate4*(hour-40)*2.5;
					printf ("The gross pay is:%.2f\n",GrossPay);
				}	
					
				if (GrossPay<=300){
     
					tax = GrossPay*TaxRate1;
					printf ("The tax is:      %.2f\n",tax);
				}
				else if (GrossPay>300&&GrossPay<=450){
     
					tax = TaxRate1*300+ (GrossPay - 300)*TaxRate2;
					printf ("The tax is:      %.2f\n",tax);
				}
				else {
     
					tax = TaxRate1*300+ TaxRate2*150+ (GrossPay-450)*TaxRate3;
					printf ("The tax is:      %.2f\n",tax);
				}
				NetPay = GrossPay - tax;
				printf ("The net pay is:  %.2f\n\n",NetPay);
				printf ("Enter the number corresponding to the desired pay rate or action:\n");
				break;
				
			case 5:
				break;
				
			default:
				printf ("the proper choices are:1,2,3,4,5\n\n");
				printf ("Enter the number corresponding to the desired pay rate or action:\n");
			}		
	}	
	return 0;	
}

你可能感兴趣的:(C语言入门,c语言)