我在图1中标记的地方后加了一条printf语句,输出结果正确,可编译运行后结果却错了(图2),怎么回事?用%.6f也一样..求解(难道是编译器的问题?用的DEV C++),源码在下面..C primer plus(第五版)7.12编程练习第8题
#include<stdio.h>
#define payRate_1 8.75 //基本工资等级
#define payRate_2 9.33
#define payRate_3 10.00
#define payRate_4 11.20
#define taxRate_1 0.15 //各级税率
#define taxRate_2 0.20
#define taxRate_3 0.25
int header(void);
int main(void)
{
int hour,option;
double totalwages,tax,payRate;
do
{
header();
scanf("%d",&option);
if(option>0&&option<5)
{
switch(option)
{
case 1: payRate=payRate_1;
break;
case 2: payRate=payRate_2;
break;
case 3: payRate=payRate_3;
break;
case 4: payRate=payRate_4;
break;
}
printf("plesse input your workinghours:");
scanf("%d",&hour);
if(hour<=40) //无加班
{
totalwages=hour*payRate;
if(totalwages>=300.00)
{
tax=(totalwages-300.00)*taxRate_2+45;
}
tax=totalwages*taxRate_1;
}
else //有加班
{
totalwages=(hour*1.5-20)*payRate;
if(totalwages>=450.00)
{
tax=(totalwages-450.00)*taxRate_3+75;
}
tax=(totalwages-300.00)*taxRate_2+45;
}
printf("totalwages\ttax\t\tnet_salary\n");
printf("%f\t%f\t%f\n",totalwages,tax,totalwages-tax);
}
else if(option>5||option<1)
printf("input error!please input again:\n");
}while(option!=5);
return 0;
}
int header(void)
{
printf("*****************************************************************\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1)$8.75/hr\t\t\t2)$9.33/hr\n");
printf("3)$10.00/hr\t\t\t4)$11.20/hr\n5)quit\n");
printf("*****************************************************************\n");
return 0;
}
#include<stdio.h>
#define payRate_1 8.75 //基本工资等级
#define payRate_2 9.33
#define payRate_3 10.00
#define payRate_4 11.20
#define taxRate_1 0.15 //各级税率
#define taxRate_2 0.20
#define taxRate_3 0.25
int header(void);
int main(void)
{
int hour,option;
double totalwages,tax,payRate;
do
{
header();
scanf("%d",&option);
if(option>0&&option<5)
{
switch(option)
{
case 1: payRate=payRate_1;
break;
case 2: payRate=payRate_2;
break;
case 3: payRate=payRate_3;
break;
case 4: payRate=payRate_4;
break;
}
printf("plesse input your workinghours:");
scanf("%d",&hour);
if(hour<=40) //无加班
{
totalwages=hour*payRate;
if(totalwages>=300.00)
{
tax=(totalwages-300.00)*taxRate_2+45;
}
tax=totalwages*taxRate_1;
}
else //有加班
{
totalwages=(hour*1.5-20)*payRate;
if(totalwages>=450.00)
{
tax=(totalwages-450.00)*taxRate_3+75;
}
tax=(totalwages-300.00)*taxRate_2+45;
}
printf("totalwages\ttax\t\tnet_salary\n");
printf("%f\t%f\t%f\n",totalwages,tax,totalwages-tax);
}
else if(option>5||option<1)
printf("input error!please input again:\n");
}while(option!=5);
return 0;
}
int header(void)
{
printf("*****************************************************************\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1)$8.75/hr\t\t\t2)$9.33/hr\n");
printf("3)$10.00/hr\t\t\t4)$11.20/hr\n5)quit\n");
printf("*****************************************************************\n");
return 0;
}