C Primer Plus第六版第七章第八题

#include<stdio.h>
#define H_WAGE1 8.75
#define H_WAGE2 9.33
#define H_WAGE3 10.00
#define H_WAGE4 11.20
#define TIME1 30
#define TIME2 40
#define RATE_T 1.5
#define RATE1 0.15
#define RATE2 0.2
#define RATE3 0.25
#define BREAK1 300
#define BREAK2 450
int main(void)
{
    float time,total,tax,net,H_WAGE;
    int choice;
    
    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("Enter the choice:\n");
	scanf("%d",&choice);
	if(choice==1||choice==2||choice==3||choice==4||choice==5)
    {
    	switch(choice)
    	{
    		case 1:
    		  H_WAGE=H_WAGE1;
    		  printf("Your choice is 1,$8.75/hr.\n");
    		  break;
    		case 2:
    		  H_WAGE=H_WAGE2;
    	  	  printf("Your choice is 2,$9.33/hr.\n");
    		  break;
    		case 3:
    		  H_WAGE=H_WAGE3;
    		  printf("Your choice is 3,$10.00/hr.\n");
    		  break;
    		case 4:
    		  printf("Your choice is 4,$11.20/hr.\n");
    	      H_WAGE=H_WAGE4;
    		  break;
    		case 5:
    		  printf("Your choice is 5,to quit.\n");
    		  H_WAGE=0;
    		  break;
    		default:
    		  printf("Enter the right number.\n");
    		  break;
			 
		}
    	
	 }
	 else 
	 printf("Enter the right number.\n");
	while(H_WAGE!=0)
	 {
	 printf("Please enter the working time per week:\n");
	
	while(scanf("%f",&time)==1)
    {
    
    	if(time>=0)
    	{
		if(time<=TIME1)
		{
		    total=time*H_WAGE;
		    tax=total*RATE1;
		}
		else if(time<TIME2)
		{
			total=time*H_WAGE;
			tax=TIME1*H_WAGE*RATE1+(time-TIME1)*H_WAGE*RATE2;
		}
		else
		{
			time=TIME2+(time-TIME2)*RATE_T;
			total=time*H_WAGE;
			if(total<BREAK2)
			    tax=TIME1*H_WAGE*RATE1+(time-TIME1)*H_WAGE*RATE2;
		    else
		        tax=TIME1*H_WAGE*RATE1+(BREAK2-BREAK1)*RATE2+(total-BREAK2)*RATE3;   
		}
		net=total-tax;
		printf("Time is %.2f hours,total income is %.2f,tax is %.2f,net income is %.2f\n"
		,time,total,tax,net);
		
		}
		else
		   printf("Time cannot be negtive.\n") ;
		printf("Enter time again or q to quit.\n");
		H_WAGE=0;
	}
}
	printf("Done!\n");
	
	return 0;
 } 
 

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值