您的位置:首页 > 编程语言

c primer plus第六版第七章编程练习

2020-04-21 21:09 52 查看
//习题八
#include<stdio.h>
#include<stdlib.h>
#define first_tax 0.15
#define second_tax 0.2
#define last_tax 0.25
#define A 8.75
#define B 9.33
#define C 10.00
#define D 11.20
#define E "quit"

void exit(int value);

void main()
{
float Allmoney,hours,tax,realmoney;
int i,j;

while(1)
{
for(i=1;i<20;i++)
printf("*");
printf("\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1)$%.2f\\hr \t 2)$%.2f\\hr \n3)$%.2f\\hr \t 4)$%.2f\\hr \n5)$%s\\hr \n",A,B,C,D,E);
for(i=1;i<20;i++)
printf("*");
printf("\n");
while(1)
{
scanf("%d",&j);
if(j>=1 && j<=4)
{
printf("How many hours you will work:");
scanf("%f",&hours);
break;
}
else if(j=5)
{
exit(1);
break;
}
else
{
printf("you wrong,enter again:");
continue;
}
}
break;
}

if(hours>40)
hours*=1.5;
switch(j)
{
case 1:Allmoney=hours*A;break;
case 2:Allmoney=hours*B;break;
case 3:Allmoney=hours*C;break;
case 4:Allmoney=hours*D;break;
default:break;
}
if(Allmoney<300)
tax=first_tax*Allmoney;
else if(Allmoney>300 && Allmoney<450)
tax=first_tax*300 + second_tax*(Allmoney-300);
else
tax=first_tax*300 + second_tax*150 + last_tax*(Allmoney-450);
realmoney=Allmoney-tax;
printf("工资总额:%.3f\t税金:%.3f\t净收入:%.3f\n",Allmoney,tax,realmoney);
}

void exit(int vaue)
{
}
//习题九
#include<stdio.h>
#define single 17850
#define head 23900
#define married 29750
#define divoiced 14875
void main()
{
float selfmoney,tax;
int i,j;
for(i=1;i<40;i++)
printf("*");
printf("\n");
printf("Please enter your state :\n");
printf("1>single\t 2>head \n3>married\t 4>divoiced\t 5>quit\n");
for(i=1;i<40;i++)
printf("*");
printf("\n");
while(1)
{
scanf("%d",&j);
if(j==5)
break;
switch(j)
{
case 1:
{
printf("enter your money:");
scanf("%f",&selfmoney);
if(selfmoney<=single)
tax=selfmoney*0.15;
else
tax=single*0.15 + (selfmoney-single)*0.28;
};break;
case 2:
{
printf("enter your money:");
scanf("%f",&selfmoney);
if(selfmoney<=head)
tax=selfmoney*0.15;
else
tax=head*0.15 + (selfmoney-head)*0.28;
};break;
case 3:
{
printf("enter your money:");
scanf("%f",&selfmoney);
if(selfmoney<=married)
tax=selfmoney*0.15;
else
tax=married*0.15 + (selfmoney-head)*0.28;
};break;
case 4:
{
printf("enter your money:");
scanf("%f",&selfmoney);
if(selfmoney<=divoiced)
tax=selfmoney*0.15;
else
tax=divoiced*0.15 + (selfmoney-head)*0.28;
};break;
default:printf("wrong data,enter again");
continue;
}
printf("selfmoney:%.2f\t tax:%.2f",selfmoney,tax);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: