#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define overtime 1.5
#define one_pg 0.15
#define two_pg 0.20
#define three_pg 0.25
char panel(void);
double compensation(double hours,double wage);
int main()
{
panel();
printf("Please select an hourly rate\n");
int a;
double hours;
double wage;
zx:scanf("%d", &a);
if (a >= 1 && a <=5)
{
switch (a)
{
case 1 :
{
printf("Please enter your working hours\n");
scanf("%f", &hours);
wage = 8.75;
compensation(hours, wage);
break;
}
case 2 :
{
printf("Please enter your working hours\n");
scanf("%f", &hours);
wage = 9.33;
compensation(hours, wage);
break;
}
case 3 :
{
printf("Please enter your working hours\n");
scanf("%f", &hours);
wage = 10.00;
compensation(hours, wage);
break;
}
case 4 :
{
printf("Please enter your working hours\n");
scanf("%f", &hours);
wage = 11.20;
compensation(hours, wage);
break;
}
case 5 :
printf("Please go to the personnel department to submit your resignation application\n");
break;
}
}
else
{
printf("Please select the correct option\n");
goto zx;
}
return 0;
}
char panel(void)
{
char s1[] = "(1)$8.75/hr";
char s2[] = "(2)$9.33/hr";
char s3[] = "(3)$10.00/hr";
char s4[] = "(4)$11.20/hr";
char s5[] = "(5)quit";
printf("*********************************************\n");
printf("%-30s", s1);
printf("%-30s\n", s2);
printf("%-30s", s3);
printf("%-30s\n", s4);
printf("%-30s\n", s5);
printf("*********************************************\n");
}
double compensation(double hours,double wage)
{
double PT_salary;
double AT_salary;
if (hours <= 40)
{
PT_salary = hours * wage;
if (PT_salary <= 300)
{
AT_salary = PT_salary * (1 - one_pg);
printf("%f\n", AT_salary);
}
else if (PT_salary > 300 && PT_salary <= 450);
{
AT_salary = 300 * (1 - one_pg) + (PT_salary - 300) * (1 - two_pg);
printf("%f\n", AT_salary);
}
}
else if (hours > 40)
{
hours = 40 + (hours - 40) * overtime;
PT_salary = hours * wage;
AT_salary = 300 * (1 - one_pg) + 150 * (1 - two_pg) + (PT_salary - 450) * (1 - three_pg);
printf("%f\n", AT_salary);
}
}
//输出结果的时候特别长两串数字
例如:
*********************************************
(1)$8.75/hr (2)$9.33/hr
(3)$10.00/hr (4)$11.20/hr
(5)quit
*********************************************
Please select an hourly rate
3
Please enter your working hours
45
-786756640795165416242917908014172073586049444062719486342463488.000000
-740476838395449803522746266366279598669223006176677163616436224.000000
scanf("%f", &hours);
改为
scanf("%lf", &hours);
double型输入要用%lf,不能用%f
float是4字节的
double是8字节的
当你输入输出的数据底数和指数都很小的时候,使用%f没问题,4个字节就涵盖了
当你的数据持续增大以后,继续使用%f就会溢出
最好还是改为%lf