|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是第一段程序:
#include <stdio.h>
#include "process.h"
#define SIZE 7
typedef struct tax_st
{
long left;
long right;
int tax;
long deduct;
}TAX_LIST;
void acceptdata(TAX_LIST tax_list[]);
void acceptdata(TAX_LIST tax_list[])
{
int i;
for(i=0;i<SIZE;i++)
{
printf("请输入个人所得税税率表第%d行数据:",i+1);
scanf("%ld",&tax_list[i].left);
scanf("%ld",&tax_list[i].right);
scanf("%ld",&tax_list[i].tax);
scanf("%ld",&tax_list[i].deduct);
}
}
void main()
{
FILE*fp;
TAX_LIST tax_list[SIZE];
if((fp=fopen("d:\\TAX.dat","wb"))==NULL)
{
printf("\ncannot open file\n");
exit(1);
}
acceptdata(tax_list);
if(fwrite(tax_list,sizeof(TAX_LIST),SIZE,fp)!=SIZE)
printf("file write error\n");
fclose(fp);
}
这是第二段程:
#include <stdio.h>
#include "process.h"
#define SIZE 7
typedef struct tax_st
{
long left;
long right;
int tax;
long deduct;
}TAX_LIST;
void calculate(TAX_LIST tax_list[])
{
double salary,s,tax,tax_free;
int i;
printf("请输入当月收入:");
scanf("%lf",&salary);
printf("请输入当月税前扣除额:");
scanf("%lf",&tax_free);
if(salary>=0)
{
s=salary-5000-tax_free;
if(s<=0)
tax=0;
else
{
for(i=0;i<SIZE-1;i++)
{
if(s<tax_list[i].right&&s>=tax_list[i].left)
{
tax=s*tax_list[i].tax/100.-tax_list[i].deduct;
break;
}
}
if(s>=tax_list[SIZE-1].left)
tax=s*tax_list[SIZE-1].tax/100.-tax_list[SIZE-1].deduct;
}
}
printf("应纳个人所得税税额是%.2lf\n",tax);
}
void main()
{
FILE*fp;
TAX_LIST tax_list[SIZE];
if((fp=fopen("d:\\TAX.dat","rb))==NULL)
{
printf("\ncannot open file\n");
exit(1);
}
if(fread(tax_list,sizeof(TAX_LIST),SIZE,fp)!=SIZE)
{
printf("file write error\n");
exit(1);
}
calculate(tax_list);
felose(fp);
}
怎么才能使他们能够组合到一起运行出最终实现的结果
|
|