C Primer plus 的一道题目
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C Primer plus 的一道题目相关的知识,希望对你有一定的参考价值。
#include<stdio.h>
#define TAX_RATE1 0.15
#define TAX_RATE2 0.2
#define TAX_RATE3 0.25
#define SALARY_RATE1 1.5
#define LEVEL1 8.75
#define LEVEL2 9.33
#define LEVEL3 10.00
#define LEVEL4 11.20
double Calculate_salary(int time,double pay)
{
double salary;
if(time<=40)
salary=time*pay;
else
salary=(time-40)*SALARY_RATE1*pay+40*pay;
return salary;
}
double Calculate_tax(double salary)
{
double tax;
if(tax<=300)
tax=salary*TAX_RATE1;
else if(tax<=450)
tax=(salary-300)*TAX_RATE2+300*TAX_RATE1;
else
tax=(salary-450)*TAX_RATE3+300*TAX_RATE1+150*TAX_RATE2;
return tax;
}
int main()
{
int choice;
int time;
double salary,tax;
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");
scanf("%d",&choice);
while(choice!=5)
{
switch(choice)
{
case 1: printf("input your work time:\n");
scanf("%d",&time);
salary=Calculate_salary(time,LEVEL1);
tax=Calculate_tax(salary);
printf("your work time is %d\n",time);
printf(" salary=%.1f tax=%.1f\n",salary,tax);
break;
case 2:
printf("input your work time:\n");
scanf("%d",&time);
salary=Calculate_salary(time,LEVEL2);
tax=Calculate_tax(salary);
printf("your work time is %d\n",time);
printf(" salary=%.1f tax=%.1f\n",salary,tax);
break;
case 3:
printf("input your work time:\n");
scanf("%d",&time);
salary=Calculate_salary(time,LEVEL3);
tax=Calculate_tax(salary);
printf("your work time is %d\n",time);
printf(" salary=%.1f tax=%.1f\n",salary,tax);
break;
case 4:
printf("input your work time:\n");
scanf("%d",&time);
salary=Calculate_salary(time,LEVEL4);
tax=Calculate_tax(salary);
printf("your work time is %d\n",time);
printf(" salary=%.1f tax=%.1f\n",salary,tax);
break;
default:printf("输入有误(1-5),请重新输入\n");
}
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");
scanf("%d",&choice);
}
}
感想 求SALARY 和TAX 我是用函数的 由于本人水平不高 不知道用什么方法好 只能这样了。
以上是关于C Primer plus 的一道题目的主要内容,如果未能解决你的问题,请参考以下文章